ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Operators
  • Use
  • Notes
  • The [ and ] operator
  • The operator [[ and ]]
  • Flexible equality and very flexible equality
  • Operators on the character strings and UNICODE
  • Position in a character string
  • WLanguage functions
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
Use
The character strings can be handled by specific WLanguage functions or by the +, [[ and ]] operators.
The operators on character strings are as follows:
  • " + ": To concatenate strings
  • " [ " and " ] ": To optionally concatenate strings
  • " [[ " and "]]" (double opening brackets and double closing brackets): Operator for extracting a substring
  • " = ": Strict equality
  • " ~= ": Flexible equality
  • " ~~ ": Very flexible equality
  • " [= ": Starts with
  • " [% %]": Dynamically built string. For more details, see String interpolation.
Texte is string = "San Francisco"
Texte[[5]]                // Retourne "F"
Texte[[5 TO 10]]           // Retourne "Franci"
Texte[[5 TO]]              // Retourne "Francisco"
Texte[[TO 10]]              // Retourne "San Franci"
Texte[[10 ON 4]]          // Retourne "isco"
Texte + " et New York"      // Retourne "San Francisco et New York"
IF Texte [= "San" THEN Trace(Texte)
Notes

The [ and ] operator

The [ and ] operator is used to optionally concatenate strings. The separator is not concatenated if the source string is an empty string ("") or if the source string ends with the separator.
For example:
  • StartString += [EndString]
    EndString is concatenated to StartString only if StartString does not end with EndString.
    For example:
    ChaîneDébut = "San Francisco"
    ChaîneFin = "Francisco"
    ChaîneDébut += [ChaîneFin]
    // ChaîneDébut contient "San Francisco"

    ChaîneDébut = "San "
    ChaîneFin = "Francisco"
    ChaîneDébut += [ChaîneFin]
    // ChaîneDébut contient "San Francisco"
  • StartString += [MiddleString] + EndString
    MiddleString is concatenated to StartString only if StartString does not end with MiddleString and if EndString does not start with MiddleString. The separator is not concatenated if the source string is an empty string ("").
    For example:
    ChaîneDébut = "C:\MesFichiers\"
    ChaîneMilieu = "\"
    ChaîneFin = "MonFichier.TXT"
    ChaîneDébut += [ChaîneMilieu] + ChaîneFin
    // ChaîneDébut contient "C:\MesFichiers\MonFichier.TXT"

    ChaîneDébut = "C:\MesFichiers"
    ChaîneMilieu = "\"
    ChaîneFin = "\MonFichier.TXT"
    ChaîneDébut += [ChaîneMilieu] + ChaîneFin
    // ChaîneDébut contient "C:\MesFichiers\MonFichier.TXT"

    ChaîneDébut = "C:\MesFichiers"
    ChaîneMilieu = "\"
    ChaîneFin = "MonFichier.TXT"
    ChaîneDébut += [ChaîneMilieu] + ChaîneFin
    // ChaîneDébut contient "C:\MesFichiers\MonFichier.TXT"
  • MyString = [StartString] + EndString
    StartString is concatenated to EndString only if EndString does not start with StartString.
    For example:
    ChaîneDébut = "Tome"
    ChaîneFin = "Tome de programmation"
    MaChaîne = [ChaîneDébut] + ChaîneFin
    // ChaîneDébut contient "Tome de programmation"

    ChaîneDébut = "Tome"
    ChaîneFin = " de programmation"
    MaChaîne = [ChaîneDébut] + ChaîneFin
    // ChaîneDébut contient "Tome de programmation"
Examples:
  • Filling a string with elements separated by CR characters (Carriage Return). The separator is not concatenated if the source string is an empty string.
    ChaîneRes is string
    FOR EACH Client
    	ChaîneRes += [CR] + Client.Nom
    END
  • Creating a file path without having to worry about the "\" characters.
    fOpen(NomRépertoire + ["\"] + NomFichier)
Related Examples:
The optional concatenation Unit examples (WINDEV): The optional concatenation
[ + ] Using the optional string concatenation
The optional concatenation is used to add a character string at the the end of another string if it does not already exist.

The operator [[ and ]]

The [[ and ]] operator allows to extract and replace a substring.
For example:
  • CHAINEAEXTRAIRE[[]]
  • STRINGTOEXTRACT[[<Position>]] = <New string>: Replaces the character found in the string by the new string.
  • EXTERNAL CHAIN[[ to ]]
  • EXTERNAL CHAIN[[ to]]
  • [[ to ]] ELECTRICAL CHAIN
  • CHAINEAEXTRAIRE[[ on ]]
Caution: If you are using a procedure that handles strings with the [[]] operators, pay great attention to the syntax used. You may inadvertently modify character strings.
For example, the following procedure can modify part of the string.
PROCEDURE P(sChaîne)
IF sChaîne THEN sChaîne="5"
// -- Appel de la procédure par la ligne :
p(sVar[[3 TO]])
To avoid modifying the initial string, the parameter must be passed by value:
  • by using brackets around the parameter in the call to the procedure,
  • by using the Local keyword in the header of the procedure.
Difference with WINDEV 7.5:
  • WINDEV: The [[]] operator used with a negative value in the second terminal returns an empty string ("").
  • WINDEV 7.5: The operator [[]] used with a negative value in the second terminal returns the complete string.
Example: Parsing a character string, character by character: EDT_HTML and EDT_TEXT are 2 edit controls.
// Variables
sChaîne is string = SAI_HTML
sCaract is string
i is int = 1
// Parcours du champ HTML
sCaract = sChaîne[[i TO i]]
WHILE i <= Length(sChaîne) 
	i++
	// ICI traitement sur sCaract 
	// Caractères suivants
	sCaract = sChaîne[[i TO i]]
END

Flexible equality and very flexible equality

The flexible equality (~=) and the very flexible equality (~~) operate on the character strings only (except for the fixed strings). These operators are used to:
  • make no difference between the uppercase characters and the lowercase characters,
  • ignore the space characters found before and after the string whose test must be run,
  • ignore the lowercase accented characters,
  • ignore the space characters and the punctuation characters inside the strings (very flexible equality only).
HFSQL equivalence: To retrieve the equivalence to the very flexible equality when performing a search on a text key in an HFSQL file, the following options must be configured when the item is described in the analysis:

Operators on the character strings and UNICODE

The available operators are as follows:
  • " + ": To concatenate strings
  • " [ " and " ] ": To optionally concatenate strings
  • " [[ " et " ]] " (double crochets ouvrants et double crochets fermants): Operator for extracting a substring
  • " [= ": Starts with
"+", "[" and "]" operators
Two UNICODE strings can be concatenated. A UNICODE string and an ANSI string cannot be concatenated.
Remark: If the concatenation of two AINSI strings is assigned to a UNICODE string (and conversely), the conversion will be implicitly performed.
Operator [[] " Et " ]
All syntaxes of the [[]] operator are available on UNICODE strings.
  • If the string passed in parameter is in ANSI format, the [[]] operator returns the result in ANSI format.
  • If the string passed in parameter is in UNICODE format, the [[]] operator returns the result in UNICODE format.
  • The position parameters and the length parameters are expressed in number of characters.
Remark: If the result of the [[]] operator on an ANSI string is assigned to a UNICODE string (and vice versa), the conversion will be implicitly performed.

Position in a character string

  • The position of the first character is set to 1 (and not to 0).
  • Position returns the start position of a specified character string inside another character string.

WLanguage functions

The character strings can also be handled by the functions:
Remark: [[]] operators are in most cases more efficient than WLanguage functions.
Related Examples:
[[ ]] operators Unit examples (WINDEV): [[ ]] operators
[ + ] Using the [[ ]] operators and the different syntaxes.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/28/2024

Send a report | Local help