FUNCTION:  String.compare

String.compare(string1, string2)
 
The String.compare function compares two given strings, ranks them based upon their lexicographic relation, and returns a 1, 0, or -1 to indicate their relative rank. By lexicographic relation, we refer to the positional relationship of the characters in the native character set. For example, a is usually ranked lower than b.
  • 1 indicates that string1 is ranked higher that string2.
  • 0 indicates that the two strings are equal in rank.
  • -1 indicates that string1 is ranked lower that string2.
The mandatory string1 parameter can be any string containing zero or more of any combination of characters and white spaces.
 
The mandatory string2 parameter can be any string containing zero or more of any combination of characters and white spaces.
 
Code for CompareExample.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   compare example
   </p>
   <do type="accept">
      <go href="CompareExample.wmls#findcompare()" />
   </do>
</card>

<card id="card2">
<p>
   string1 = $(string1)
   <br />
   string2 = $(string2)
   <br />
   rank = $(rank)
</p>
</card>

</wml>

 
Code for CompareExample.wmls
extern function findcompare()
{
   var str1 = Dialogs.prompt("Enter string1", "");
   var str2 = Dialogs.prompt("Enter string2", "");
   var rnk = String.compare(str1, str2);
   WMLBrowser.setVar("string1", str1);
   WMLBrowser.setVar("string2", str2);
   WMLBrowser.setVar("rank", rnk);
   WMLBrowser.go("CharAtExample.wml#card2");
};


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information