2019-11-18 14:31:44 +01:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: trim - Functions - Configuration Language
|
|
|
|
description: >-
|
|
|
|
The trim function removes the specified set of characters from the start and
|
|
|
|
end of
|
|
|
|
|
2019-11-18 14:31:44 +01:00
|
|
|
a given string.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `trim` Function
|
|
|
|
|
2021-10-22 23:42:17 +02:00
|
|
|
`trim` removes the specified set of characters from the start and end of the given
|
2019-11-18 14:31:44 +01:00
|
|
|
string.
|
|
|
|
|
2021-10-22 23:42:17 +02:00
|
|
|
```hcl
|
|
|
|
trim(string, str_character_set)
|
|
|
|
```
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
Every occurrence of a character in the second argument is removed from the start
|
|
|
|
and end of the string specified in the first argument.
|
2021-10-22 23:42:17 +02:00
|
|
|
|
2019-11-18 14:31:44 +01:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> trim("?!hello?!", "!?")
|
2021-10-22 23:42:17 +02:00
|
|
|
"hello"
|
|
|
|
|
|
|
|
> trim("foobar", "far")
|
|
|
|
"oob"
|
|
|
|
|
|
|
|
> trim(" hello! world.! ", "! ")
|
|
|
|
"hello! world."
|
2019-11-18 14:31:44 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`trimprefix`](/language/functions/trimprefix) removes a word from the start of a string.
|
|
|
|
* [`trimsuffix`](/language/functions/trimsuffix) removes a word from the end of a string.
|
|
|
|
* [`trimspace`](/language/functions/trimspace) removes all types of whitespace from
|
2019-11-18 14:31:44 +01:00
|
|
|
both the start and the end of a string.
|