|
|
|
|
|
- Use
- Notes
- The [ and ] operator
- The [[]] operator
- Loose equality and very loose equality
- Operators on the character strings and UNICODE
- Position in a character string
- WLanguage functions
Operators on character strings
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 " ] ": For optional concatenation of strings.
- " [[ " and "]]" (double opening brackets and double closing brackets): Sub-string extraction operator
- " = "Strict equality
- " ~= ": Flexible equality
- " ~~ "Very flexible equality
- " [= "Starts with
- " [% %]"Dynamic string construction. For more details, see String interpolation.
Text is string = "San Francisco"
Text[[5]]
Text[[5 TO 10]]
Text[[5 TO]]
Text[[TO 10]]
Text[[10 ON 4]]
Text + " and New York"
IF Text [= "San" THEN Trace(Text)
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:
StartString = "San Francisco"
EndString = "Francisco"
StartString += [EndString]
StartString = "San "
EndString = "Francisco"
StartString += [EndString]
- 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:
StartString = "C:\MyFiles\"
MiddleString = "\"
EndString = "MyFile.TXT"
StartString += [MiddleString] + EndString
StartString = "C:\MyFiles"
MiddleString = "\"
EndString = "\MyFile.TXT"
StartString += [MiddleString] + EndString
StartString = "C:\MyFiles"
MiddleString = "\"
EndString = "MyFile.TXT"
StartString += [MiddleString] + EndString
- MyString = [StartString] + EndString
StartString is concatenated to EndString only if EndString does not start with StartString. For example:
StartString = "Type"
EndString = "Type of programming"
MyString = [StartString] + EndString
StartString = "Type"
EndString = " of programming"
MyString = [StartString] + EndString
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.
ResString is string
FOR EACH Customer
ResString += [CR] + Customer.Name
END
- Creating a file path without having to worry about the "\" characters.
fOpen(DirectoryName + ["\"] + FileName)
Related Examples:
|
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 The [[]] operator is used to extract and replace a substring. For example: - STRINGTOEXTRACT[[<Position>]]
- CHAINEAEXTRAIRE[[<Position>]] = <Nouvelle chaîne>: Replaces the string character with the new string..
The above-mentioned syntax is not available in this version. - STRINGTOEXTRACT[[<Start> to <End>]]
- STRINGTOEXTRACT[[<Start> to]]
- STRINGTOEXTRACT[[to <End>]]
- STRINGTOEXTRACT[[<Start> on <Number>]]
Caution: If you use a procedure that manipulates strings with the operators [[]], beware of the following syntax. You may inadvertently modify character strings. For example, the following procedure can modify part of the string. PROCEDURE P(sString)
IF sString THEN sString="5"
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 Browse a character string, character by character: SAI_HTML and SAI_TEXTE are 2 Edit control fields.
sString is string = EDT_HTML
sCharact is string
i is int = 1
sCharact = sString[[i TO i]]
WHILE i <= Length(sString)
i++
sCharact = sString[[i TO i]]
END
Loose equality and very loose equality The loose equality (~=) and the very loose 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 loose equality only).
HFSQL equivalence HFSQL Equivalence: To retrieve the very flexible equality equivalence when searching on a text key in an HFSQL data file, it is necessary to configure the following options when describing the field in the analysis: Operators on the character strings and UNICODE The available operators are as follows: - " + ": To concatenate strings
- " [ "and " ] "For optional concatenation of strings
- " [[ " and " ]] "(double hook opening and double hook closing): Sub-string extraction operator
- " [= ": Starts with
"+", "[" and "]" operators Two UNICODE strings can be concatenated. A UNICODE string and an ANSI string cannot be concatenated. Note: If the concatenation of two AINSI strings is assigned to a UNICODE string (and Reverse), the conversion will be implicitly performed. "[[" and "]]" operator All the syntaxes of the [[]] operator are available for the Unicode strings. - If the string passed as parameter is in ANSI format, the result returned by the [[]] operator will be in ANSI format.
- If the string passed as parameter is in Unicode format, the result returned by the [[]] operator will be 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: Note operators [[]] are in most cases more efficient than WLanguage functions.
Related Examples:
|
Unit examples (WINDEV): [[ ]] operators
[ + ] Using the [[ ]] operators and the different syntaxes.
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|