The Replace family of functions is used to scan text (strings) (especially the contents of .html files) and replace certain non-terminal symbols with new values.
A non-terminal symbol is a sequence of characters representing a CW expression surrounded by begin- and end- delimiters. The begin-delimiter and end-delimiter default to <? and ?>. In an .html file these are coded as <? and ?>. For more information on how Web browsers (and HTML editors) treat special characters, see Character Entities.
If you desire to use alternate begin- and end-delimiters, set the values of SpecialVariables["BeginExpression"] and SpecialVariables["EndExpression"]
The Replace functions are:
string Replace(string input, args ...) // replace using SpecialVariables delimiters
string Replace1(string input, args ...) // replace with (Non-encoded) <? and ?>
string Replace2(string input, string bs, string es, args ...) // specify delimiters explicitly
The arguments beginning at args are optional arguments. If they are specified, they may be referenced using the expressions arg[0], arg[1], arg[2], etc.
| a = '456'; b = '123<?a?>789'; c = Replace1(b); Client << c; // browser shows "123456789" |
The expression within the delimiters may be any CW expression including function calls and local and global variables.
| a1 = 450; a2 = 6; b = '123<?a1 + a2?>789'; c = Replace1(b); Client << c; // browser shows "123456789" |
You may supply optional arguments:
| b = '<?arg[0]?, arg[1]?, arg[2]?>'; c = Replace1(b, 'abc', 'def', 'ghi'); Client << c; // browser shows "abc, def, ghi" |
If you are reading a file created by an HTML editor, you probably want to use the standard (<?, ?>) delimiters. Use the Replace function.
| b =GetFile("x.html"); c = Replace1(b, 'abc', 'def', 'ghi'); Client << c; // browser shows "abc, def, ghi" |
You may replace the begin and end delimiters depending on your requirements.
| SpecialVariables["BeginExpression"] = "aaa"; SpecialVariables["EndExpression"] = "bbb"; a = "Hello, world." b = 'aaaabbb'; c = Replace(b); Client << c; // browser shows "Hello, world." |