Объявление : Все некоммерческие проекты, зарегистрированные для использования Earth Engine до
15 апреля 2025 года, должны
подтвердить некоммерческое право на сохранение доступа к Earth Engine.
ee.String.index
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Ищет первое вхождение подстроки в строке. Возвращает индекс первого совпадения или -1.
Использование | Возврат | String. index (pattern) | Целое число |
Аргумент | Тип | Подробности | это: target | Нить | Строка для поиска. |
pattern | Нить | Строка, которую нужно найти. |
Примеры
Редактор кода (JavaScript)
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
Настройка Python
Информацию об API Python и использовании geemap
для интерактивной разработки см. на странице «Среда Python» .
import ee
import geemap.core as geemap
Colab (Python)
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 "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 UTC."],[[["\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```"]]