---
title: "trim function in Strata | Oplema"
description: "Remove spaces from both ends of text, leaving the characters between them unchanged. For example, trim('  hello  ') returns 'hello'."
url: "https://oplema.com/docs/strata/functions/trim"
updated: "2026-11-04"
---

# trim

Remove spaces from both ends of text. Pass a second argument to remove those characters instead.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **VARCHAR**.

### Expression

```
trim('  hello  ')
```

### Result

```
'hello'
```

To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | hello |

## Arguments and types

```
trim(string, characters)
```

**string**

Text

**characters**

Text

Supported signatures (2)

```
trim(string: VARCHAR) → VARCHAR
trim(string: VARCHAR, characters: VARCHAR) → VARCHAR
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

If the first argument is missing, the result is NULL.

## Related functions

[ltrim

Remove spaces from the start of text. Pass a second argument to remove those characters instead.

](https://oplema.com/docs/strata/functions/ltrim)[rtrim

Remove spaces from the end of text. Pass a second argument to remove those characters instead.

](https://oplema.com/docs/strata/functions/rtrim)[translate

Swap individual characters: each character in the second argument becomes the character at the same position in the third. Characters with no counterpart are removed.

](https://oplema.com/docs/strata/functions/translate)[substring

Extract part of text, starting at a character position where 1 is the first character. Without a length, it continues to the end of the text.

](https://oplema.com/docs/strata/functions/substring)

[Browse text](https://oplema.com/docs/strata/functions#text) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/text.html#trimstring-characters)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
