ee.String.trim
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trả về một chuỗi có giá trị là chuỗi ban đầu, trong đó mọi khoảng trắng ở đầu và cuối đều bị xoá.
Cách sử dụng | Giá trị trả về |
---|
String.trim() | Chuỗi |
Đối số | Loại | Thông tin chi tiết |
---|
this: string | Chuỗi | Chuỗi cần cắt. |
Ví dụ
Trình soạn thảo mã (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"
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
cho quá trình phát triển tương tác.
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"
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\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```"]]