Skip to content

rtrim - Remove whitspace from string end

The rtrim function will remove whitespace from the end of a given string value, but not from the start.

Syntax

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

rtrim(value: string): string
value: string.rtrim(): string

Arguments

NameTypeRequiredDescription
valuestringtrueThe string to be trimmed

Example - Cleaning up an extracted username

Consider the following document:

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

We want to extract the username from this string, so that we can search and query it directly. This can be done using the extract keyword with a regular expression.

extract message into my_data using regexp(e=/user (?<user>.*) has logged in/)

This results in this log object:

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

Notice the trailing space at the end of the username. This is because a stray space has made its way in. We can use rtrim to clean this up:

replace my_data.user with rtrim(my_data.user)
replace my_data.user with my_data.user.rtrim()

This will remove the trailing space from the username and result in a cleaner value.