Nested strings and special characters for DataWindow object properties

DataWindow property values often involve specifying strings within strings. Embedded quotation marks need special treatment so that the strings are parsed correctly. This treatment varies depending on the programming language you are using.


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.

    "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.

    "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:

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:

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 (\r\n).

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:

dw_1.Modify("benefits.EditMask.SpinRange='0~~~~10'")

More information

For more information about nested strings and special characters, see PowerScript Reference.

Nested strings and special characters in JavaScript for DataWindow object properties

Different processing by language and DataWindow

JavaScript uses different characters from those used within the DataWindow to delimit strings and identify special characters. For DataWindow object properties, several levels of nested strings and two types of delimiter can create a complicated expression.

In JavaScript, strings are delimited by double quotes and the escape character in strings is the backslash (\). The escape character allows you to include double quotes and special characters within a string. The DataWindow can use either double or single quotes to delimit strings and uses tilde (~) as an escape character.

Because some parts of the string are parsed by the language and some by the DataWindow, strings passed to the DataWindow often use both types of escape character. The one to use depends on whether the DataWindow or the external language will evaluate the character. The external language deals with the outer string and converts escape sequences to the corresponding special characters. Nested strings are dealt with by the DataWindow parser.

Guidelines

Observe these guidelines for each type of character:

  • Special characters use the language escape character. Tabs, newlines, and carriage returns are \t, \n, \r

  • Nested double quotes require the language escape character (\) so they won't be interpreted as the closure of the opening double quote. Depending on the level of nesting, they may also require the DataWindow escape character (~).

  • Single quotes for nested strings do not need the language escape character, but depending on the level of nesting they may need the DataWindow escape character.

  • Tildes are specified in odd-numbered groups. They do not interact with the language escape character in counting the number of escape characters used.

Examples

Both of these JavaScript examples are valid ways of nesting a string:

dw_1.Modify("DataWindow.Crosstab.Values=\"empname\"");
dw_1.Modify("DataWindow.Crosstab.Values='empname'");

The following three JavaScript statements specify the same string. They show a string with three levels of nesting using different combinations of escape characters and quote types. In the first example, note the escaping of the inner quote with a tilde for the DataWindow and a backslash for the language:

dw_1.Modify("emp_id.Color=\"16777215 \t If (emp_status=~\"A~\",255,16777215)\"");
 
dw_1.Modify("emp_id.Color=\"16777215 \t If (emp_status='A',255,16777215)\"");
 
dw_1.Modify("emp_id.Color='16777215 \t If (emp_status=\"A\",255,16777215)'");

The corresponding example in PowerBuilder is:

dw_1.Modify("emp_id.Color = ~"16777215 ~t If (emp_status=~~~"A~~~",255,16777215)~"")

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). In code, the value is in a nested string and needs a tilde escape character. The two tildes are interpreted as a single tilde when parsed by the DataWindow:

dw_1.modify("benefits.EditMask.SpinRange='0~~10'");