Google many times only found on foreign websites have prompted how to compare Chinese, the original address: http://www.webdeveloper.com/forum/showthread.php? T = 9365
Prerequisites: unicode encoding is used. If other GBK encoding methods are used, this method should not work!
Localecompare () method
Definition and usage
Compares two strings in a specific local order.
Syntax
stringObject.localeCompare(target)
Parameters |
Description |
Target |
String to be compared with stringobject in a specific local order. |
Return Value
Number of the comparison result. If stringobject is smaller than target, localecompare () returns a number smaller than 0. If the value of stringobject is greater than target, this method returns a value greater than 0. If the two strings are equal or there is no difference according to the local sorting rules, this method returns 0.
Test 1:
VaR STR = "Beijing ";
VaR var2 = "Beijing ";
VaR res = Str. localecompare (var2 );
Console. Log (RES );
Output 0, equal
Test 2:
VaR STR = "Monday ";
VaR var2 = "Tuesday ";
VaR res = Str. localecompare (var2 );
Console. Log (RES );
Output 1