ee.String.trim

  • The trim() method removes leading and trailing whitespace from a string.

  • The method takes the string itself as input and returns a new string with whitespace removed.

  • Examples demonstrate trim() usage in both JavaScript and Python environments.

Returns a string whose value is the original string, with any leading and trailing whitespace removed.

UsageReturns
String.trim()String
ArgumentTypeDetails
this: stringStringThe string to trim.

Examples

Code Editor (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"

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)

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"