ee.String.index
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
یک رشته را برای اولین وقوع یک زیررشته جستجو می کند. شاخص اولین مسابقه یا -1 را برمیگرداند.
استفاده | برمی گرداند | String. index (pattern) | عدد صحیح |
استدلال | تایپ کنید | جزئیات | این: target | رشته | رشته مورد جستجو |
pattern | رشته | رشته برای پیدا کردن. |
نمونه ها
ویرایشگر کد (جاوا اسکریپت)
print(ee.String('abc123').index('')); // 0
print(ee.String('abc123').index('c1')); // 2
print(ee.String('abc123').index('ZZ')); // -1
// index is case-sensitive.
print(ee.String('abc123').index('BC')); // -1
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
print(ee.String('abc123').index('').getInfo()) # 0
print(ee.String('abc123').index('c1').getInfo()) # 2
print(ee.String('abc123').index('ZZ').getInfo()) # -1
# index is case-sensitive.
print(ee.String('abc123').index('BC').getInfo()) # -1
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe \u003ccode\u003eindex()\u003c/code\u003e method searches a string for the first occurrence of a specified substring and returns the index of the first match.\u003c/p\u003e\n"],["\u003cp\u003eIf the substring is not found, the method returns -1.\u003c/p\u003e\n"],["\u003cp\u003eThe search performed by \u003ccode\u003eindex()\u003c/code\u003e is case-sensitive.\u003c/p\u003e\n"],["\u003cp\u003eThe method can be used in both JavaScript and Python environments within the Earth Engine platform.\u003c/p\u003e\n"],["\u003cp\u003eAn empty string pattern will return 0 as the index.\u003c/p\u003e\n"]]],["The `index` function searches a string (`target`) for a specified substring (`pattern`). It returns the integer index of the first matching substring's start position. If no match is found, it returns -1. The function is case-sensitive. An empty `pattern` will always return an index of 0. The provided examples illustrate the usage and expected return values.\n"],null,["# ee.String.index\n\nSearches a string for the first occurrence of a substring. Returns the index of the first match, or -1.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------------|---------|\n| String.index`(pattern)` | Integer |\n\n| Argument | Type | Details |\n|----------------|--------|-----------------------|\n| this: `target` | String | The string to search. |\n| `pattern` | String | The string to find. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.String('abc123').index('')); // 0\nprint(ee.String('abc123').index('c1')); // 2\nprint(ee.String('abc123').index('ZZ')); // -1\n\n// index is case-sensitive.\nprint(ee.String('abc123').index('BC')); // -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('abc123').index('').getInfo()) # 0\nprint(ee.String('abc123').index('c1').getInfo()) # 2\nprint(ee.String('abc123').index('ZZ').getInfo()) # -1\n\n# index is case-sensitive.\nprint(ee.String('abc123').index('BC').getInfo()) # -1\n```"]]