ee.String.replace
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
یک رشته جدید را با برخی یا همه موارد منطبق از یک الگوی جایگزین شده برمیگرداند.
استفاده | برمی گرداند | String. replace (regex, replacement, flags ) | رشته |
استدلال | تایپ کنید | جزئیات | این: input | رشته | رشته ای که در آن جستجو می شود. |
regex | رشته | عبارت منظم برای مطابقت. |
replacement | رشته | رشته ای که جایگزین رشته فرعی منطبق می شود. |
flags | رشته، پیش فرض: "" | رشتهای که ترکیبی از پرچمهای عبارات منظم را مشخص میکند، بهویژه یک یا چند مورد از: 'g' (تطابق جهانی) یا 'i' (بحث نادیده گرفته شود) |
نمونه ها
ویرایشگر کد (جاوا اسکریپت)
print(ee.String('abc-abc').replace('abc', 'X')); // X-abc
print(ee.String('abc-abc').replace('abc', 'X', 'g')); // X-X
print(ee.String('abc-abc').replace('abc', '', 'g')); // -
print(ee.String('aBc-Abc').replace('abc', 'Z', 'i')); // Z-Abc
print(ee.String('aBc-Abc').replace('abc', 'Z', 'ig')); // Z-Z
راه اندازی پایتون
برای اطلاعات در مورد API پایتون و استفاده از geemap
برای توسعه تعاملی به صفحه محیط پایتون مراجعه کنید.
import ee
import geemap.core as geemap
کولب (پایتون)
print(ee.String('abc-abc').replace('abc', 'X').getInfo()) # X-abc
print(ee.String('abc-abc').replace('abc', 'X', 'g').getInfo()) # X-X
print(ee.String('abc-abc').replace('abc', '', 'g').getInfo()) # -
print(ee.String('aBc-Abc').replace('abc', 'Z', 'i').getInfo()) # Z-Abc
print(ee.String('aBc-Abc').replace('abc', 'Z', 'ig').getInfo()) # Z-Z
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe \u003ccode\u003ereplace()\u003c/code\u003e method returns a new string with instances of a given pattern replaced by a specified replacement string.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts a regular expression or a string to define the pattern to be replaced and the replacement string.\u003c/p\u003e\n"],["\u003cp\u003eOptional flags can be used to control the behavior of the replacement, such as performing a global replacement ('g') or ignoring case ('i').\u003c/p\u003e\n"],["\u003cp\u003eThe method is available for Earth Engine String objects in both JavaScript and Python environments.\u003c/p\u003e\n"]]],["The `String.replace()` method replaces substrings within a string. It takes a `regex` (pattern), `replacement` string, and optional `flags`. The input string is searched for the `regex` pattern, and matched substrings are replaced by the `replacement`. Flags, like 'g' for global or 'i' for case-insensitive matching, modify the replacement behavior. The output is the modified string, the original string is not modified. The function operates the same for Javascript and Python.\n"],null,["# ee.String.replace\n\nReturns a new string with some or all matches of a pattern replaced.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------------------------------------|---------|\n| String.replace`(regex, replacement, `*flags*`)` | String |\n\n| Argument | Type | Details |\n|---------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| this: `input` | String | The string in which to search. |\n| `regex` | String | The regular expression to match. |\n| `replacement` | String | The string that replaces the matched substring. |\n| `flags` | String, default: \"\" | A string specifying a combination of regular expression flags, specifically one or more of: 'g' (global match) or 'i' (ignore case) |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.String('abc-abc').replace('abc', 'X')); // X-abc\nprint(ee.String('abc-abc').replace('abc', 'X', 'g')); // X-X\nprint(ee.String('abc-abc').replace('abc', '', 'g')); // -\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'i')); // Z-Abc\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'ig')); // Z-Z\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('abc-abc').replace('abc', 'X').getInfo()) # X-abc\nprint(ee.String('abc-abc').replace('abc', 'X', 'g').getInfo()) # X-X\nprint(ee.String('abc-abc').replace('abc', '', 'g').getInfo()) # -\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'i').getInfo()) # Z-Abc\nprint(ee.String('aBc-Abc').replace('abc', 'Z', 'ig').getInfo()) # Z-Z\n```"]]