Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.String.slice

  • TheString.slice() method returns a substring of the given string.

  • If the specified range exceeds the string's length, a shorter substring is returned.

  • Thestart argument is the inclusive beginning index and can be negative to count from the end.

  • Theend argument is the exclusive ending index, defaults to the string's length, and can also be negative.

Returns a substring of the given string. If the specified range exceeds the length of the string, returns a shorter substring.

UsageReturns
String.slice(start,end)String
ArgumentTypeDetails
this:stringStringThe string to subset.
startIntegerThe beginning index, inclusive. Negative numbers count backwards from the end of the string.
endInteger, default: nullThe ending index, exclusive. Defaults to the length of the string. Negative numbers count backwards from the end of the string.

Examples

Code Editor (JavaScript)

print(ee.String('').slice(0));// ''print(ee.String('').slice(-1));// ''vars=ee.String('abcdefghijklmnopqrstuvwxyz');print(s.slice(0));// abcdefghijklmnopqrstuvwxyzprint(s.slice(24));// yzprint(s.slice(-3));// xyzprint(s.slice(3,3));// ''print(s.slice(2,3));// cprint(s.slice(-4,25));// wxy

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

display(ee.String('').slice(0))# ''display(ee.String('').slice(-1))# ''s=ee.String('abcdefghijklmnopqrstuvwxyz')display(s.slice(0))# abcdefghijklmnopqrstuvwxyzdisplay(s.slice(24))# yzdisplay(s.slice(-3))# xyzdisplay(s.slice(3,3))# ''display(s.slice(2,3))# cdisplay(s.slice(-4,25))# wxy

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-07-13 UTC.