2019-11-18 14:31:44 +01:00
|
|
|
---
|
2020-08-15 03:51:06 +02:00
|
|
|
layout: "language"
|
2019-11-18 14:31:44 +01:00
|
|
|
page_title: "trim - Functions - Configuration Language"
|
|
|
|
sidebar_current: "docs-funcs-string-trim"
|
|
|
|
description: |-
|
2021-10-22 23:42:17 +02:00
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
|
|
|
Every occurrence of a character in the second argument is removed from the start
|
|
|
|
and end of the string specified in the first argument.
|
|
|
|
|
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
|
|
|
|
|
|
|
|
* [`trimprefix`](./trimprefix.html) removes a word from the start of a string.
|
|
|
|
* [`trimsuffix`](./trimsuffix.html) removes a word from the end of a string.
|
|
|
|
* [`trimspace`](./trimspace.html) removes all types of whitespace from
|
|
|
|
both the start and the end of a string.
|