WMLScript compare() function

The compare() function compares two strings and returns a value representing the comparison result.

The compare() function can return the following values:

  • -1 (if string1 < string2)
  • 0 (if string1 = string2)
  • 1 (if string1 > string2)

Syntax

n = String.compare(string1, string2)
Component Description
n The integer returned from the function.
string1 A string.
string2 A string.

Example

var a = String.compare("world","world");
var b = String.compare("I","world");
var c = String.compare("world","I");

Result

a = 0
b = -1
c = 1