Name
compare — Compare two strings
Usage
String.compare(str1, str2)
: Stringstr1
: Stringstr2
Description
Compares two strings lexicographically. Returns -1
if str1
is less than
str2
, 1
if
str1
is greater than
str2
, and 0
if they are
equal. If one string is a prefix of the other, the shorter string is
the lesser one.
Returns invalid
if either argument can’t be
converted to a string.
Examples
String compare("one", "two")
returns integer -1
String.compare("two", "three")
returns integer 1
String.compare("four", "four")
returns integer 0
String.compare("six", "sixteen")
returns integer -1
String.compare(6, 16)
returns integer 1
String.compare(invalid, "foo")
returns invalid
String.compare("foo", invalid)
returns invalid
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.