ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / 
  • Single-line string literal
  • Declaring a single-line string literal
  • Examples
  • Multiline string literal
  • Declaring a multiline string literal
  • Examples
  • Advantages of syntaxes 1, 2 and 3
  • Limitations
  • String interpolation (dynamic string building)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
String literals: single-line and multiline strings
String literals are used to represent and manipulate data as a sequence of characters. For example, string literals can be used to display information, define a constant, etc.
WINDEV, WINDEV Mobile and WEBDEV provide a number of tools for entering strings over both single or multiple lines. You can also build strings dynamically.
Single-line string literal

Declaring a single-line string literal

A string literal can be declared:
  • by enclosing the string in double quotation marks.
  • New in version 2024
    by enclosing the string in backticks ( ` character, also known as "backquote" or "grave accent").

Single-line string literal with double quotation marks Hide the details

<Variable name> = "<String content>"
<">:
Symbol indicating the beginning of the single-line string literal.
<String content>:
Single-line string literal.
To include double quotation marks (") within the string, you need to double them.
Caution: The project options determine if the [% %] characters can be used. For more details, see String interpolation (dynamic string building).
<">:
Symbol indicating the end of the single-line string literal.
New in version 2024

Single-line string literal with backticks ( ` ) Hide the details

<Variable name> = `<String content>`
<`>:
Symbol indicating the beginning of the single-line string literal (backtick).
<String content>:
Single-line string literal.
To include backticks ( ` ) within the string, you need to double them.
Caution: You can use [% %] characters to display the contents of the variable they enclose. For more details, see String interpolation (dynamic string building).
<`>:
Symbol indicating the end of the single-line string literal (backtick).

Examples

// Single-line string literal with double quotation marks
MySingleLineString is string
MySingleLineString = "Example line of text"

// String with double double quotation marks
MySingleLineString2 is string
MySingleLineString 2 = "The ""General Terms and Conditions"" option must be checked"
// Displays: The "General conditions" option must be checked
New in version 2024
// Single-line string literal with backticks ( ` )
MySingleLineString is string
MySingleLineString = `Example line of text`
Multiline string literal

Declaring a multiline string literal

As its name suggests, a multiline string literal can consist of several lines. There are different syntaxes used to manipulate this type of strings:
  • [ and ] symbols.
  • double quotation marks.
  • New in version 2024
    backticks ( ` ).
  • the "CR" (Carriage Return) character between the various lines of the multiline string.

Multiline string literal with [ ] Hide the details

<Variable name> = [
                <String content>
                <String content 2>
                ]
<[>:
Symbol indicating the beginning of the multiline string. This symbol must be followed by a carriage return. This carriage return is ignored in the string.
<String content>:
Multiline string, over multiple lines, without double quotation marks. Carriage returns between 2 lines of the string are interpreted as line breaks. Tabs at the beginning of lines are ignored. Tabs on the last line ar allowed.
Caution: The project options determine if the [% %] characters can be used. For more details, see String interpolation (dynamic string building).
<]>:
Symbol indicating the end of the multiline string. This symbol must be preceded by a carriage return. This carriage return is ignored in the string.

Multiline string literal with double quotation marks Hide the details

<Variable name> = "
                <String content>
                <String content 2>
                "
<">:
Symbol indicating the beginning of the multiline string. This symbol must be followed by a carriage return. This carriage return is ignored in the string.
<String content>:
Multiline string, over multiple lines, without double quotation marks. Carriage returns between 2 lines of the string are interpreted as line breaks. Tabs at the beginning of lines are taken into account.
Caution: The project options determine if the [% %] characters can be used. For more details, see String interpolation (dynamic string building).
<">:
Symbol indicating the end of the multiline string. This symbol must be preceded by a carriage return. This carriage return is ignored in the string.
New in version 2024

Multiline string literal with backticks ( ` ) Hide the details

<Variable name> = `
                <String content>
                <String content 2>
                `
<`>:
Symbol indicating the beginning of the multiline string. This symbol must be followed by a carriage return. This carriage return is ignored in the string.
<String content>:
Multiline string, spanning multiple lines, with or without double quotation marks. Carriage returns between 2 lines of the string are interpreted as line breaks. Tabs at the beginning of lines are taken into account.
Benefit: You can use [% %] characters to automatically display the contents of the variable they enclose. For more details, see String interpolation (dynamic string building).
<`>:
Symbol indicating the end of the multiline string. This symbol must be preceded by a carriage return. This carriage return is ignored in the string.

Multiline string literal with Carriage Return Hide the details

<Variable> = "<String content>"+ CR + ...
                       "<String content 2>"
<String content>:
Multiline string, spanning multiple lines, with double quotation marks for each line. Lines are separated by "+ CR + ...".

Examples

// Use square brackets to write a multiline string
MyString is string
MyString = [
	Example of 
	multiline string
	]
MyString is string
MyString = [
	Example of 
	multiline string
	]
// Use Carriage Return to write a multiline string
MyString is string
MyString = "This is a " + CR + "multiline string"

Advantages of syntaxes 1, 2 and 3

  • Syntax highlighting: by default, multiline strings are colored purple (like any other string enclosed in double quotation marks in WLanguage) and highlighted in mauve.
    You can use the default WLanguage syntax highlighting ("Syntax highlighting .. WLanguage" in the context menu of the multiline string). This option is used to check the code typed when a multiline string is used for the dynamic compilation (Compile).
  • Ability to collapse/expand a multiline string
    Collapsing multiline strings frees up space in the code editor. The code becomes clearer and more readable. When the string is collapsed, its content is displayed in a tooltip.
  • Additional advantage of syntax 2
    Double quotation marks make strings more readable, regardless of whether they are single-line or multiline strings.

Limitations

  • The maximum number of lines in a multiline string is set to 1000.
  • You cannot use multiline strings within multiline strings. The following code generates a WLanguage error:
    sCode is string = [
    sMultilineString is string = [
    Test on the multiline strings
    Attempt on the multiline strings
    ]
    ]
String interpolation (dynamic string building)
String interpolation consists in combining variables (or expressions) and strings. WLanguage offers various methods to perform this operation:
  • Method 1: Split the string literal to include the variable.
    Examples:
    sCode is string = "The " + sVar + " string is a string"

    s is string = [
    	the string
    	] + var + [
    	is multiline
    	]

    s is string = "
    	the string
    	" + var + "
    	is multiline
    	"

    This solution is not recommended, especially if the string is to be translated.
  • Method 2: Use the StringBuild function. Values that can take parameters must be replaced with %1, %2, %n, etc., in the string literal.
    Examples:
    sCode is string = "The %1 string is a string"
    sCode = StringBuild(sCode, MyVariable)

    sString is string = [
    	the %1 string
    	is multiline
    	]
    sString = StringBuild(sString, MyVariable)

    sString is string = "
    	the %1 string
    	is multiline
    	"
    sString = StringBuild(sString, MyVariable)
  • Method 3: "Allow "[% %]" in strings" option.
    • In the project description window, on the "Compilation" tab, check Allow "[% %]" in strings.
    • Use the following syntax to indicate the expression to use:
      [%VariableName or Expression%]
      For example:
      // Ask for customer confirmation
      IF YesNo(Yes, "Do you confirm the creation of customer [%sCustomerName%]") = No THEN
      	RETURN
      END
    Remarks:
    • New in version 2024
      If you use multiline string literals with backticks ( ` ), the expressions that use "[% %]" are automatically interpreted. You don't need to check the corresponding option in the "Compilation" tab.
    • If the option is not checked in the "Compilation" tab of the project description window, the string appears as it is: the name of the variable (or expression) appears in the string.
    • Use "-%" before the "[% %]" characters to prevent them from being interpreted. Some WLanguage functions require this specific syntax. Example:
      grTooltip(GR_Deadline, grTooltipFormat, "[%CATEGORY%]" + CR + CR+ "[%VALUE%]" + " H")
      becomes
      grTooltip(GR_Deadline, grTooltipFormat, -%"[%CATEGORY%]" + CR + CR + -%"[%VALUE%]" + " H")
    • When translating this type of strings, the name of the variable (or expression) inside [% %] must not be changed. However, you can move the [%VariableName or Expression%] tag within the string.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/26/2024

Send a report | Local help