trim_space

This page explains how to use the trim_space function in APL.

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.

Usage

Syntax

trim_space(value)

Parameters

NameTypeDescription
valuestringThe input string to trim.

Returns

A string with all leading and trailing whitespace removed. The function doesn't 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

['sample-http-logs']
| extend cleaned_uri = trim_space(uri)
| summarize count() by cleaned_uri

Run in Playground

Output

cleaned_uricount
/api/data120
/api/data/submit88
/login42

This query removes leading and trailing spaces from each uri and aggregates request counts by the cleaned path.

In OpenTelemetry traces, service names or span IDs can have unintended spaces when injected from external tools. Use trim_space to standardize span IDs before filtering.

Query

['otel-demo-traces']
| extend clean_span_id = trim_space(span_id)
| summarize count() by clean_span_id

Run in Playground

Output

clean_span_idcount
53c9e2f4e8794a6a17
a3ff4f1e5b9d1c2214
12c4b9f7da984dc721

This query trims each span_id and aggregates span counts, ensuring ID formatting does not affect grouping.

Other query languages