公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.String.compareTo
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
按字典顺序比较两个字符串。返回:如果两个字符串在字典编排上相等,则返回 0;如果 string1 小于 string2,则返回 -1;如果 string1 在字典编排上大于 string2,则返回 1。
用法 | 返回 |
---|
String.compareTo(string2) | 整数 |
参数 | 类型 | 详细信息 |
---|
此:string1 | 字符串 | 要比较的字符串。 |
string2 | 字符串 | 要比较的字符串。 |
示例
代码编辑器 (JavaScript)
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 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003ecompareTo\u003c/code\u003e 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.\u003c/p\u003e\n"],["\u003cp\u003eThis method can be used on both client-side (JavaScript) and server-side (Python) Earth Engine environments and takes two string arguments for comparison.\u003c/p\u003e\n"],["\u003cp\u003eThe output is an Integer value (\u003ccode\u003e-1\u003c/code\u003e, \u003ccode\u003e0\u003c/code\u003e, or \u003ccode\u003e1\u003c/code\u003e) representing the comparison results.\u003c/p\u003e\n"]]],[],null,["# ee.String.compareTo\n\nCompares 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.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------|---------|\n| String.compareTo`(string2)` | Integer |\n\n| Argument | Type | Details |\n|-----------------|--------|----------------------------|\n| this: `string1` | String | The string to compare. |\n| `string2` | String | The string to be compared. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.String('a').compareTo('b')); // -1\nprint(ee.String('a').compareTo('a')); // 0\nprint(ee.String('b').compareTo('a')); // 1\n\nprint(ee.String('a').compareTo(ee.String('b'))); // -1\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nprint(ee.String('a').compareTo('b').getInfo()) # -1\nprint(ee.String('a').compareTo('a').getInfo()) # 0\nprint(ee.String('b').compareTo('a').getInfo()) # 1\n\nprint(ee.String('a').compareTo(ee.String('b')).getInfo()) # -1\n```"]]