公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.String.trim
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
:傳回值為原始字串的字串,並移除所有前置和後置空格。
引數 | 類型 | 詳細資料 |
---|
這個:string | 字串 | 要修剪的字串。 |
範例
程式碼編輯器 (JavaScript)
var s = ee.String('\t\n\r abc\t\n\r ');
print(s.trim()); // "abc"
var s = ee.String(' a\t\n\r b ');
print(s.trim()); // "a\t\n\r b"
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
s = ee.String('\t\n\r abc\t\n\r ')
print(s.trim().getInfo()) # "abc"
s = ee.String(' a\t\n\r b ')
print(s.trim().getInfo()) # "a\t\n\r b"
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003etrim()\u003c/code\u003e removes leading and trailing whitespace characters (spaces, tabs, newlines, carriage returns) from a string.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns a new string without modifying the original string.\u003c/p\u003e\n"],["\u003cp\u003eInternal whitespace characters within the string are preserved.\u003c/p\u003e\n"]]],["The `trim()` method removes leading and trailing whitespace from a string. It operates on a string (specified as `this: string`) and returns a new string with whitespace characters like tabs, newlines, and carriage returns removed from the beginning and end. Whitespace within the string remains unchanged. Examples in JavaScript and Python demonstrate trimming strings, showing the output after applying `trim()`.\n"],null,["# ee.String.trim\n\nReturns a string whose value is the original string, with any leading and trailing whitespace removed.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------|---------|\n| String.trim`()` | String |\n\n| Argument | Type | Details |\n|----------------|--------|---------------------|\n| this: `string` | String | The string to trim. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nvar s = ee.String('\\t\\n\\r abc\\t\\n\\r ');\nprint(s.trim()); // \"abc\"\n\nvar s = ee.String(' a\\t\\n\\r b ');\nprint(s.trim()); // \"a\\t\\n\\r b\"\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\ns = ee.String('\\t\\n\\r abc\\t\\n\\r ')\nprint(s.trim().getInfo()) # \"abc\"\n\ns = ee.String(' a\\t\\n\\r b ')\nprint(s.trim().getInfo()) # \"a\\t\\n\\r b\"\n```"]]