Nested strings and special
characters for DataWindow object properties
Tilde (~) is the escape character that allows you to nest quoted
strings within other quoted strings and to specify special characters
such as tabs and carriage returns. For DataWindow object properties,
several levels of nested strings can create a complicated
expression.
Techniques for quoting nested
strings
Both double and single quotes are valid delimiters for strings.
You can use this fact to simplify the specification of nested
strings.
There are two ways to embed a string within another string. You
can:
-
Use the other type of quotation mark for the nested string.
If the main string uses double quotes, the nested string can use
single quotes.1"If(state='MA',255,0)" -
Use the escape character to specify that a quote is part of
the string instead the closure of a previous quote.1"If(state=~"MA~",255,0)"
If the string includes a third level of nested strings, you need
to add another tilde which must be accompanied by its own escape
character, a second tilde. This is the reason that tildes are usually
specified in odd numbers (1, 3, or 5 tildes).
This Modify expression (entered on a single line in code) shows
three levels of nested strings:
1 2 |
dw_1.Modify( "DataWindow.Color = '255 ~t If(state= ~'MA~',255,0)'") |
This version of the expression has more tildes because there are
no single quotes:
1 |
dw_1.Modify("DataWindow.Color = ~"255 ~t If(state= ~~~"MA~~~",255,0)~"") |
Common special
characters
Strings can also include special characters, as shown in the
previous example. This table lists the special characters that are
most often used in DataWindow expressions.
Escape sequence |
Meaning |
---|---|
~t |
Tab |
~r |
Carriage return |
~n |
Newline or linefeed |
~” |
Double quote |
~’ |
Single quote |
~~ |
Tilde |
A line break is a carriage return plus a newline (
).
Special use of tilde
A special case of specifying tildes involves the
EditMask.SpinRange property, whose value is two numbers separated by a
tilde (not an escape character, simply a tilde). To specify this value
in a script, you must use a nested string with four tildes, which is
interpreted as a single tilde when parsed:
1 |
dw_1.Modify("benefits.EditMask.SpinRange='0~~~~10'") |
More information
For more information about nested strings and special
characters, see PowerScript Reference.