2019-11-18 14:31:44 +01:00
|
|
|
---
|
2021-11-23 00:57:25 +01:00
|
|
|
layout: "language"
|
|
|
|
page_title: "trim - Functions - Configuration Language"
|
|
|
|
sidebar_current: "docs-funcs-string-trim"
|
|
|
|
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-11-23 00:57:25 +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-11-23 00:57:25 +01:00
|
|
|
* [`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
|
2019-11-18 14:31:44 +01:00
|
|
|
both the start and the end of a string.
|