Xbasic

js_escape Function

Syntax

C result = js_escape(text as C [,flags as C])

Arguments

textCharacter

Original string

flagsCharacter

U - encode as Unicode, UTF8 - encode as Unicode, assume that input is UTF8

Description

Formats a string so it will be properly encoded for use in Javascript.

Discussion

Escapes a string so it can be embedded in javascript safely. Returns the escaped string.

Example

dim str as c =<<%str%
Strings containing ' (single quotes) need to be properly escaped for inclusion in javascript.
	Tabs and new lines are also escaped.
%str%

? js_escape(str)
= "Strings containing \' (single quotes) need to be properly escaped for inclusion in javascript.\n\tTabs and new lines are also escaped.\n"

See Also