---
title: "trim | Grafana Agent documentation"
description: "Learn about trim"
---

# trim

`trim` removes the specified set of characters from the start and end of a string.

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
trim(string, str_character_set)
```

## Examples

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
> trim("?!hello?!", "!?")
"hello"

> trim("foobar", "far")
"oob"

> trim("   hello! world.!  ", "! ")
"hello! world."
```
