2018-05-06 21:32:16 -04:00
|
|
|
---
|
2023-09-15 10:03:23 -04:00
|
|
|
sidebar_label: split
|
2018-05-06 21:32:16 -04:00
|
|
|
description: |-
|
|
|
|
|
The split function produces a list by dividing a given string at all
|
2019-03-21 15:20:29 -04:00
|
|
|
occurrences of a given separator.
|
2018-05-06 21:32:16 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# `split` Function
|
|
|
|
|
|
2019-03-21 15:20:29 -04:00
|
|
|
`split` produces a list by dividing a given string at all occurrences of a
|
2018-05-06 21:32:16 -04:00
|
|
|
given separator.
|
|
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
|
split(separator, string)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
> split(",", "foo,bar,baz")
|
|
|
|
|
[
|
|
|
|
|
"foo",
|
|
|
|
|
"bar",
|
|
|
|
|
"baz",
|
|
|
|
|
]
|
|
|
|
|
> split(",", "foo")
|
|
|
|
|
[
|
|
|
|
|
"foo",
|
|
|
|
|
]
|
|
|
|
|
> split(",", "")
|
|
|
|
|
[
|
|
|
|
|
"",
|
|
|
|
|
]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
|
2024-04-24 07:24:30 -04:00
|
|
|
* [`join`](../../language/functions/join.mdx) performs the opposite operation: producing a string
|
2018-05-06 21:32:16 -04:00
|
|
|
joining together a list of strings with a given separator.
|