The three main characters that users will probably need to use and which will require the escape character are the single quote character ('), the double quote character (") and the backslash character (\).
Escaping these characters is easy, simply place a preceding backlash character (\) in front of the character within the string which you want to have treated literally. Thus, \' would allow usage of a single quote character, \" would allow usage of the double quote character and \\ would allow literal use of a backslash character in a string.
var userName = "Jerome "The Race" Anderson";
This statement would produce the following error message output:
gs.log('Please retry the operation, the expected button wasn't found on the form.');
would generate the following error due to the special character found in the string:
The following statement would not necessarily generate an error, however, it would most probably not produce the expected results.
var filepath = "\\bzavr\extra\open\files\config.ini";
The filepath variable, as stored in memory would actually contain the following string text:
Thus, the previous statements could be re-written as the following to prevent any issues which might be introduced by including these special characters in a string:
var userName = "Jerome \"The Race\" Anderson";
gs.log('Please retry the operation, the expected button wasn\'t found on the form.');
var filepath = "\\\\bzavr\\extra\\open\\files\\config.ini";
|Escaped Character||Character Representation|
For example the following statement,
var textData = "This is a test string.\n\rNext Line.\tShifted line.";
when printed, might show output similar to the following:
This is a test string. Next Line. Shifted line.