Skip to main content
Use the trim_space function in APL to remove leading and trailing whitespace characters from a string. This function is especially useful when cleaning up input from logs, APIs, or user-generated content where strings may contain unintended spaces. You can apply trim_space to normalize data before comparisons, joins, or aggregations that depend on exact string matches. Use trim_space when you need to ensure that extraneous spaces at the beginning or end of a string don’t interfere with your analysis or results.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk, the trim function removes leading and trailing spaces. APL’s trim_space works similarly.
In ANSI SQL, the TRIM() function removes leading and trailing whitespace by default. APL’s trim_space achieves the same behavior.

Usage

Syntax

Parameters

Returns

A string with all leading and trailing whitespace removed. The function does not modify internal whitespace.

Use case examples

When analyzing request URIs from logs, trailing or leading spaces can lead to false negatives in equality comparisons. Use trim_space to normalize request paths.Query
Run in PlaygroundOutputThis query removes leading and trailing spaces from each uri and aggregates request counts by the cleaned path.