Skip to content

ltrim - Remove whitspace from string start

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

Syntax

ltrim(value: string): string

Arguments

Name Type Required Description
value string true The string to trim

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 leading space at the start of the username. This is because a stray space has made its way in. We can use ltrim to clean this up:

replace my_data.user with my_data.user.ltrim()

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