Escaped Strings |
Top Previous Next |
Important: If you have a Pro License and use the Pipeline Runner Studio script creator and runner tool you have the ability to let Studio escape your strings for you automatically, either within the string itself or using a separate dialog. This can make life VERY easy where complicated strings are concerned. In the real world text can include any character. However, there are many situations in many programming languages where important characters cannot be used inside a declared string and Pipeline Runner is no different.
The simplest escaped string would be a path and file name, which should be surrounded by quotation marks when passed to the Windows operating system command line so that it knows to treat the result as one piece of text rather than as space separated segments of text.
In Pipeline Runner your scripts will need to use escaped strings in situations where not doing so would break the processing. For example, where a string is surrounded with double quotes, you cannot include any further double quotes inside the string or there would be an imbalance in the number of quotation marks. If you were to include two quotation marks inside a string that was already delimited with double quotes it would think that it was two strings and cause an error since only one string can be assigned to a string variable.
To illustrate the point, this example script line would work perfectly:
Var:TestString,"This is a string."
However, as soon as you add additional quotation marks the script line would generate an error:
Var:TestString,"This is a "string"."
As far as Pipeline Runner is concerned you are trying to create two strings and a bit of text that it would not understand. If you break down the string around the double quotes you would get this:
1."This is a " 2.string 3."."
There are other characters that can be included in strings that have special meanings, including \n (new line),\r (carriage return) and \t (horizontal tab),
There are three ways to deal with this issue:
Escape Character
Pipeline Runner supports the use of an Escape Character \ (backslash) which can be placed in a string immediately before any special characters to include then in a string. You can make the example string above that generates an error work correctly by prepending each double quote with the escape character:
Var:TestString,"This is a \"string\"."
If there are a lot of characters that need to be escaped, for example with a long path and file name, escaping them all can be labour intensive and error prone, but luckily in most case an alternative is available.
Verbatim String Literal Character
Pipeline Runner supports the use of a Verbatim String Literal Character $ (dollar sign) to indicate that a string literal is to be interpreted verbatim. The following example defines two identical file paths, one using a regular string literal and the other using a verbatim string literal. This is one of the more common uses of verbatim string literals:
Var:FilePath,$"C:\Test\Test Text.txt"
Var:FilePath,"C:\\Test\\Test Text.txt" Important: The Verbatim String character only works with special characters. You cannot use it to allow double quotes in a string so you must escape any special characters and the quotes individually. Here are examples: Escape Using Repeat Characters
Pipeline Runner also supports the use of repeated characters to define an escape sequence. The following example illustrates the effect of defining a regular string literal and a verbatim string literal that contain identical character sequences:
Var:TestString,"This is a \"string\"."
Var:TestString,@"This is a ""string""."
See Also: Reserved Characters Escape Selected Text
|