A DataFlex string token can consist of many different styles. But 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, so long as the embedded quotes are different to the string operators used to delimit the string.
The most commonly used character strings use the "text" and 'text' notation using the double- and single-quote.
Some more examples of these are:
"The quick brown fox"
'jumped over the lazy dog... 3 times!'
"Frank says 'hello'."
'Susan says "Hi".'
""
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 white space on the left, which may result in extra white space inside the resulting string.
String sPhrase
Move @"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary" to sPhrase
results in a string that contains (note the white space on the left of lines 2 - 4):
"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary"
The """ operator performs the same behavior as the @ operator, but without the white space on the left, as it aligns the text at the ending operator.
"""
Hello World!
"""
String sPhrase
Move """
My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary
""" to sPhrase
results in a string that contains (no white space on the left of any line):
"My Summer Reading List:
- We Are Legion
- Ringworld
- Project Hail Mary"
Unlimited single quotes and up to 2 consecutive double quotes can be used inside a """ string.
Example:
"""
Reading List:
'John': "Dune" and "The Martian"
'Anne': "The Time Machine", "Ready Player One" and "2001: A Space Odyssey"
"""
All string operators have an @(SQL) version. While using the @SQL operator, the Studio provides SQL CodeSense and should help the developer using SQL. The same rules apply for the underlying-operators meaning that when using @SQL no command/macro and register emplacements 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 white space 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
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 might result in weird 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. Like for example "2210". In this particular case, it is the instruction number of the current line.
Using @ or """ strings negates the command/macro parameter and register emplacement.
@"Test !A"
@'Test !A'