Escape Sequences

A string variable is created by enclosing a text sequence within double quotes:

str = "this is a string";

If the string needs to contain special characters, including the double quote character itself, the special characters are prefixed with an escape sequence consisting of a backslash (\) following by an exclamation mark (!).

Here are some examples of escape sequences – the ones in bold are the ones that I use often:

escape-codes

Examples:

str1 = " \!"Hello World\!" "
str2 = "\!Nline 1\!Nline 2\!N"

If you are constructing a text string that has embedded within it a large number of double quotes there is an alternate notation that can be used:

str = " ... \[ ... ]\ ... "

Everything between the brackets does not need or support escape sequences.

Example:

str = "\[ "Hello World" ]\"

 

Share the joy:
facebooktwittergoogle_pluslinkedinmailfacebooktwittergoogle_pluslinkedinmail

One thought on “Escape Sequences”

Leave a Reply