PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Use
  • Notes
  • The [ and ] operator
  • The [[ and ]] operator
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 sub-string
  • " = ": Strict equality
  • " ~= ": Flexible equality
  • " ~~ ": Very flexible equality
  • " [= ": Starts with
Text is string = "San Francisco"
Text[[5]]                // Returns "F"
Text[[5 TO 10]]           // Returns "Franci"
Text[[5 TO]]              // Returns "Francisco"
Text[[TO 10]]              // Returns "San Franci"
Text[[10 on 4]]          // Returns "isco"
Text + " and New York"      // Returns "San Francisco and New York"
IF Text [= "San" THEN Trace(Text)
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.
Some examples:
  • 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 contains "San Francisco"

    StartString = "San "
    EndString = "Francisco"
    StartString += [EndString]
    // StartString contains "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:
    StartString = "C:\MyFiles\"
    MiddleString = "\"
    EndString = "MyFile.TXT"
    StartString += [MiddleString] + EndString
    // StartString contains "C:\MyFiles\MyFile.TXT"

    StartString = "C:\MyFiles"
    MiddleString = "\"
    EndString = "\MyFile.TXT"
    StartString += [MiddleString] + EndString
    // StartString contains "C:\MyFiles\MyFile.TXT"

    StartString = "C:\MyFiles"
    MiddleString = "\"
    EndString = "MyFile.TXT"
    StartString += [MiddleString] + EndString
    // StartString contains "C:\MyFiles\MyFile.TXT"
  • 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 contains "Type of programming"

    StartString = "Type"
    EndString = " of programming"
    MyString = [StartString] + EndString
    // StartString contains "Type of programming"
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:
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 [[ and ]] operator

The [[ and ]] operator is used to extract and replace a sub-string.
WEBDEV - Browser code The [[ and ]] operator is used to extract a sub-string only.
Some examples:
  • STRINGTOEXTRACT[[<Position>]]
  • STRINGTOEXTRACT[[<Position>]] = <New String>: Replaces the character found in the string by the new string.
    WEBDEV - Browser code 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 are using a procedure that handles the strings with the [[]] operators, pay attention to the syntax used. You may modify your character strings without being aware of it.
For example, the following procedure can modify part of the string.
PROCEDURE P(sString)
IF sString THEN sString="5"
// -- Call to the procedure via the line:
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 second bound returns an empty string ("").
  • WINDEV 7.5: The [[]] operator used with a negative value in second bound returns the full string.
Example: Parsing a character string, character by character: EDT_HTML and EDT_TEXT are 2 edit controls.
// Variables
sString is string = EDT_HTML
sCharact is string
i is int = 1
// Browse the HTML control
sCharact = sString[[i TO i]]
WHILE i <= Length(sString)
        i++
        // Process on sCharact here
        // Next characters
        sCharact = sString[[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 a HFSQL file, the following options must be configured when the item is described in the analysis:
WEBDEV - Browser code The "Very flexible equality" operator is not available in browser code.

Operators on the character strings and UNICODE

The available operators are as follows:
  • " + ": To concatenate strings
  • " [ " and " ] ": To optionally concatenate strings
  • " [[ " and " ]] " (double opening brackets and double closing brackets): Operator for extracting a sub-string
  • " [= ": Starts with
"+", "[" and "]" operator
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 conversely), the conversion will be implicitly performed.
"[[" and "]]" operator
All the syntaxes of the [[]] operator are available for the Unicode strings.
  • If the string passed in parameter is in ANSI format, the result returned by the [[]] operator will be in ANSI format.
  • If the string passed in 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.
Note: If the result of the [[]] operator on an ANSI string is assigned to a UNICODE string (and conversely), 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: in most cases, the [[]] operators are more efficient than the 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
EXAMPLE
Procedure StringCountAscii(Texto,Caracter)

x, qtde is int = 0

ntotal is int = Length(Texto)

LOOP(ntotal)
x++
IF Texto[[x]] = Charact(Caracter) // 34 = aspa dupla //58 = : dois pontos
qtde++
END
END

RESULT qtde
BOLLER
06 Dec. 2019