ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • Equivalence between StringCompare and comparison operators
  • Comparing numeric values
  • Characters taken into account for punctuation and spaces
  • StringCompare and UNICODE
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
Compares two strings character by character:
  • according to the sequence of ASCII characters.
  • according to the alphabetical order.
Example
MyString1 is string = "Developing is fantastic"
MyString2 is string = "Developing is simple"
ResultCompare is int = StringCompare(MyString1, MyString2)
// ResultCompare = -1: the character 'f' comes before the character 's'
Syntax
<Result> = StringCompare(<First string> , <Second string> [, <Options>])
<Result>: Integer
  • 0 if the character strings are equal.
  • -1 if the characters in <First string> come before the characters in <Second string> according to the ASCII order or to the lexicographic order.
  • 1 if the characters in <First string> come after the characters in <Second string> according to the ASCII order or to the lexicographic order.
<First string>: Character string
Character string to compare.
<Second string>: Character string
Character string to compare.
<Options>: Optional constant (or combination of constants)
Comparison options:
ccIgnoreAccentCompares strings ignoring accented characters.
WEBDEV - Browser code This constant is not available.
ccIgnoreCaseCompares strings ignoring the case (uppercase/lowercase characters).
ccIgnoreInsideSpaceCompares strings ignoring spaces within the strings.
AndroidAndroid Widget JavaPHP This constant is not available.
ccIgnorePunctuationAndSpaceCompares strings ignoring punctuation and spaces (see Notes for more details).
WEBDEV - Browser code This constant is not available.
ccIgnoreSpaceCompares strings ignoring spaces before and after the strings.
ccLexicographicOrderCompares strings in lexicographical order (for example, 'é' is between 'e' and 'f').
WEBDEV - Browser codePHP This constant is not available.
ccNormal
(default value)
Standard comparison, similar to the '=' operator.
ccRespectNumericCompares strings taking into account the numeric values within the strings (in this case, "10" comes after "9").
Remarks

Equivalence between StringCompare and comparison operators

  • = operator:
    The = operator is equivalent to the following code: StringCompare(<String1>, <String2>, ccNormal)
  • ~= operator:
    The ~= operator is equivalent to the following code: StringCompare(<String1>, <String2>, ccIgnoreCasse, + ccIgnoreAccent + ccIgnoreSpace)
    WEBDEV - Browser code This syntax is not available.
  • ~~ operator:
    The ~~ operator is equivalent to the following code: StringCompare(<String1>, <String2>, ccIgnoreCasse + ccIgnoreAccent + ccIgnorePonctuationAndSpace)
    WEBDEV - Browser code This syntax is not available.
  • <, >, <= and >= operators:
    These operators are equivalent to the following code: StringCompare(<String1>, <String2>, ccLexicographicOrder)
    WEBDEV - Browser code This syntax is not available.
For more details on comparison operators, see Comparison operators.
Reports and QueriesWindowsLinuxUniversal Windows 10 AppAndroidAndroid Widget JavaUser code (UMC)Ajax

Comparing numeric values

The ccRespectNumeric constant sorts by taking into account the numeric value represented by digits and not just the alphabetical order of the numbers.
Without the ccRespectNumeric constant, the strings below will be sorted in the following order: "string1", "string10", "string2"
With the ccRespectNumeric constant, the same strings will be sorted in this order: "string1", "string2", "string10"
Examples of comparison performed with and without the ccRespectNumeric constant:
Sorting strings containing digits without the ccRespectNumeric constantSorting strings containing digits with the ccRespectNumeric constant
000
000
001001
00901
011
010009
0909
19
10010
1110
911
Sorting strings containing digits without the ccRespectNumeric constantSorting strings containing digits with the ccRespectNumeric constant
10.00Aa7.00Aa
10.01Gh7.01Ba
10.50Ag7.01Dfe
11.00Aa7.50Fg
7.00Aa7.51Tga
7.01Ba8.00Aa
7.01Dfe8.01Gjk
7.50Fg8.01Ty
7.51Tga8.50Ze
8.00Aa9.00Aa
8.01Gjk9.80Er
8.01Ty9.99Zaaa
8.50Ze10.00Aa
9.00Aa10.01Gh
9.80Er10.50Ag
9.99Zaaa11.00Aa

Characters taken into account for punctuation and spaces

The characters taken into account for punctuation and spaces are provided by the system. To get the list of these characters, write the following WLanguage code:
s is string
FOR i = 0 TO 255
IF Charact(i) <> StringFormat(Charact(i), ccIgnorePunctuationAndSpace) THEN
 s += Charact(i)
END
END
Info(s)
ToClipboard(s)
Reports and QueriesWindowsLinuxUniversal Windows 10 AppAndroidAndroid Widget JavaUser code (UMC)PHPAjax

StringCompare and UNICODE

You have the ability to use ANSI strings, Unicode strings and buffers in the different parameters of the function.
The following conversion rule is used for the Ansi systems (Windows or Linux):
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • If the first condition is not met and there is at least one Unicode string, all the strings are converted to Unicode and the operation is performed in Unicode (the conversion is performed with the current character set, if necessary).
  • Otherwise, the operation is performed in Ansi.
The conversion rule used for Unicode systems is as follows:
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • Otherwise, the operation is performed in Unicode.
For more details on UNICODE, see Managing UNICODE.
Reminder: The linguistic parameters used are defined during the call to ChangeCharset.
Business / UI classification: Neutral code
Component: wd290vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help