ee.String.slice
Stay organized with collections
Save and categorize content based on your preferences.
Returns a substring of the given string. If the specified range exceeds the length of the string, returns a shorter substring.
Usage | Returns | String.slice(start, end) | String |
Argument | Type | Details | this: string | String | The string to subset. |
start | Integer | The beginning index, inclusive. Negative numbers count backwards from the end of the string. |
end | Integer, default: null | The 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)); // ''
var s = ee.String('abcdefghijklmnopqrstuvwxyz');
print(s.slice(0)); // abcdefghijklmnopqrstuvwxyz
print(s.slice(24)); // yz
print(s.slice(-3)); // xyz
print(s.slice(3, 3)); // ''
print(s.slice(2, 3)); // c
print(s.slice(-4, 25)); // wxy
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
print(ee.String('').slice(0).getInfo()) # ''
print(ee.String('').slice(-1).getInfo()) # ''
s = ee.String('abcdefghijklmnopqrstuvwxyz')
print(s.slice(0).getInfo()) # abcdefghijklmnopqrstuvwxyz
print(s.slice(24).getInfo()) # yz
print(s.slice(-3).getInfo()) # xyz
print(s.slice(3, 3).getInfo()) # ''
print(s.slice(2, 3).getInfo()) # c
print(s.slice(-4, 25).getInfo()) # wxy
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]