ee.String.compareTo
Compares two strings lexicographically. Returns: the value 0 if the two strings are lexicographically equal; -1 if string1 is less than string2; and 1 if string1 is lexicographically greater than string2.
Usage | Returns |
---|
String.compareTo(string2) | Integer |
Argument | Type | Details |
---|
this: string1 | String | The string to compare. |
string2 | String | The string to be compared. |
Examples
print(ee.String('a').compareTo('b')); // -1
print(ee.String('a').compareTo('a')); // 0
print(ee.String('b').compareTo('a')); // 1
print(ee.String('a').compareTo(ee.String('b'))); // -1
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
print(ee.String('a').compareTo('b').getInfo()) # -1
print(ee.String('a').compareTo('a').getInfo()) # 0
print(ee.String('b').compareTo('a').getInfo()) # 1
print(ee.String('a').compareTo(ee.String('b')).getInfo()) # -1
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-03-19 UTC.
[null,null,["Last updated 2024-03-19 UTC."],[[["`compareTo` lexicographically compares two strings, returning 0 if they are equal, -1 if the first string is less than the second, and 1 if the first string is greater than the second."],["This method can be used on both client-side (JavaScript) and server-side (Python) Earth Engine environments and takes two string arguments for comparison."],["The output is an Integer value (`-1`, `0`, or `1`) representing the comparison results."]]],[]]