ee.String.index
Searches a string for the first occurrence of a substring. Returns the index of the first match, or -1.
Usage | Returns | String.index(pattern) | Integer |
Argument | Type | Details | this: target | String | The string to search. |
pattern | String | The string to find. |
Examples
Code Editor (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 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
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
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 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["The `index()` method searches a string for the first occurrence of a specified substring and returns the index of the first match."],["If the substring is not found, the method returns -1."],["The search performed by `index()` is case-sensitive."],["The method can be used in both JavaScript and Python environments within the Earth Engine platform."],["An empty string pattern will return 0 as the index."]]],[]]