ee.String.replace

แสดงผลสตริงใหม่ที่มีการแทนที่การจับคู่บางส่วนหรือทั้งหมดของรูปแบบ

การใช้งานการคืนสินค้า
String.replace(regex, replacement, flags)สตริง
อาร์กิวเมนต์ประเภทรายละเอียด
ดังนี้ inputสตริงสตริงที่จะค้นหา
regexสตริงนิพจน์ทั่วไปที่จะจับคู่
replacementสตริงสตริงที่แทนที่สตริงย่อยที่ตรงกัน
flagsString, ค่าเริ่มต้น: ""สตริงที่ระบุชุดค่าผสมของแฟล็กนิพจน์ทั่วไป โดยเฉพาะอย่างยิ่งแฟล็กอย่างน้อย 1 รายการต่อไปนี้ "g" (การจับคู่ทั่วโลก) หรือ "i" (ไม่คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่)

ตัวอย่าง

โปรแกรมแก้ไขโค้ด (JavaScript)

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

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

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