Xbasic

*ADDSLASHES Function

Syntax

New_String as C = *ADDSLASHES(B bytes[,C escape[,C replace]])

Arguments

New_String

A string with escaped quote characters.

bytes

A string containing characters to be translated.

escape

A string containing the characters to be translated.

replace

A string containing the replacement characters. This string must be in the same order as the Escapestring.

Description

Quotes a BLOB (escapes NIL characters) -- allows user to chose what to escape and what to replace with.

Discussion

Adds backslash characters before quote characters, so they can be used in expression strings. The *ADDSLASHES() function has custom quotation rules that allow you to generated quoted strings for other languages, such as JavaScript and HTML. It allows binary (blob) data to be quoted (with the NULL terminator replaced with a "\0". By default it converts chr(13)to "\r", chr(10)to "\n" and chr(26)to "\Z".

Example

dim cc as C
 
cc = "filter = " + chr(34) + "Edward" + chr(34)
 
? cc
= filter = "Edward"
 
? *addslashes(cc)
= filter = \"Edward\"
 
? *addslashes("crlf = "+crlf() +" control-z = "+chr(26)) 
= "crlf = \r\n control-z = \Z"

Optionally define what characters (other than NULL) get mapped. Here is an example that maps chr(9)to "\t" and chr(8)to "\b".

? *addslashes("crlf = " + crlf() + " control-z = " + chr(26) + " tab = " + chr(9) + " chr(8) = " + chr(8), crlf() + chr(26) + chr(9) + chr(8), "rnZtb") 
= "crlf = \r\n control-z = \Z tab = \t chr(8) = \b"

See Also