Character Strings
A DataFlex string token can consist of many different styles. Generally, a string is a sequence of zero or more typeable characters, enclosed by two string operators.
Whichever string operators you use must match at both ends of the string. This allows you to type a string with embedded quote marks, as long as the embedded quotes are different from the string operators used to delimit the string.
Conventional Strings
The most commonly used character strings utilize the "text" and 'text' notation using double- and single-quotes. Here are some examples:
"The quick brown fox"
'jumped over the lazy dog... 3 times!'
"Frank says 'hello'."
'Susan says "Hi".'
""
Multiline Strings
DataFlex provides the @ operator to support multiline strings.
@"Hello
World"
@"The quick brown fox
jumped over the lazy dog...
3 times!"
The @ operator keeps any whitespace on the left, which may result in extra whitespace inside the resulting string.
String sPhrase
Move @"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary" to sPhrase
This results in a string that contains (note the whitespace on the left of lines 2 - 4):
"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary"
Aligned Multiline Strings
The """ operator performs the same behavior as the @ operator, but without the whitespace on the left, as it aligns the text at the ending operator.
"""
Hello World!
"""
Rules for the """ operator:
- If used on a single line, it works like an
@string. '\r\n'(carriage return followed by a line feed) represents a new line.- If spanning multiple lines:
- On the first line, to the right of the
""", there should be only whitespace. - On the last line, to the left of the
""", there should be only whitespace. - The ending operator is used to specify the alignment. Whitespace before this is removed on the lines above.
- If these rules are not followed, the compiler will indicate which rule is not checked.
String sPhrase
Move """
My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary
""" to sPhrase
This results in a string that contains (no whitespace on the left of any line):
"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary"
Embedded Quotes
Unlimited single quotes and up to two consecutive double quotes can be used inside a """ string. For example:
"""
Reading List:
'John': "Dune" and "The Martian"
'Anne': "The Time Machine", "Ready Player One" and "2001: A Space Odyssey"
"""
@SQL Strings
All string operators have an @(SQL) version. While using the @SQL operator, the Studio provides SQL CodeSense to assist the developer using SQL. The same rules apply for the underlying operators, meaning that when using @SQL, no command/macro and register placements are performed.
Examples of @SQL notation are:
@SQL"SELECT * FROM Customer WHERE Customer.Name = 'John Doe'"
@SQL'SELECT * FROM Customer WHERE Customer.Name = "John Doe"'
@SQL""" SELECT * FROM Customer WHERE Customer.Name = 'John Doe' """
When embedding foreign code like SQL, JavaScript, or HTML into DataFlex code, you can use a multiline string. A new style of multiline string has been added that allows better alignment with the rest of your code without adding all this whitespace to the actual string at runtime. These strings use the triple quote notation and have the advantage that you can embed quotes in your source code.
Get
SQLExecDirect
of
ghoSQLExecutor
@SQL"""
SELECT
Phone_Number
FROM
Customer
WHERE
Customer_Number
=
33
"""
to
aResult
Move
"""
function hello(sName){
window.alert("Hello: " + sName);
}
hello("world");
"""
to
sJavaScript
Macro Expansion using !
Something to be aware of is that conventional single-operator strings (strings embedded in only single or double quotes) have one particularity. When ! followed by one sequential letter or digit is used, it might result in unexpected text in the string at runtime.
This is because command/macro parameters and registers can be inserted this way. An example of this is !a, which will result in what seems to be a random number, such as "2210". In this particular case, it is the instruction number of the current line.
Using @ or """ strings negates the command/macro parameter and register placement.
@"Test !A"
@'Test !A'