Skip to content

trim

Description

Removes whitespace from both the start and end of a string.

Syntax

Like many functions in DataPrime, trim supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

trim(value: string): string
(value: string).trim(): string

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to trim

Example

Clean up an extracted username

Consider the following document:

{
  "message": "user  Chris  has logged in"
}

Extracting the username produces spaces at the beginning and end:

{
  "message": "user  Chris  has logged in",
  "my_data": {
    "user": " Chris "
  }
}

Use trim to remove the extra spaces:

replace my_data.user with trim(my_data.user)
replace my_data.user with my_data.user.trim()

Output

{
  "message": "user  Chris  has logged in",
  "my_data": {
    "user": "Chris"
  }
}