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 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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