O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

compare — Compare two strings

Usage

String.compare(str1, str2)

str1 : String

str2 : String

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required