ee.String.compareTo
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
دو رشته را از نظر لغوی مقایسه می کند. برمی گرداند: مقدار 0 اگر دو رشته از نظر لغوی برابر باشند. -1 اگر string1 کمتر از string2 باشد. و 1 اگر string1 از نظر واژگانی بزرگتر از string2 باشد.
استفاده | برمی گرداند | String. compareTo (string2) | عدد صحیح |
استدلال | تایپ کنید | جزئیات | این: string1 | رشته | رشته ای برای مقایسه |
string2 | رشته | رشته ای که باید مقایسه شود. |
نمونه ها
ویرایشگر کد (جاوا اسکریپت)
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
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
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
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\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```"]]