You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/website/content/docs/templates/hcl_templates/functions/string/split.mdx

44 lines
1.2 KiB

---
page_title: split function reference
description: |-
The `split` function divides the given string according to the specified separator to produce a list.
---
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!IMPORTANT]
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
# `split` Function
`split` produces a list by dividing a given string at all occurrences of a
given separator.
```hcl
split(separator, string)
```
## Examples
```shell-session
> split(",", "foo,bar,baz")
[
"foo",
"bar",
"baz",
]
> split(",", "foo")
[
"foo",
]
> split(",", "")
[
"",
]
```
## Related Functions
- [`join`](/packer/docs/templates/hcl_templates/functions/string/join) performs the opposite operation: producing a string
joining together a list of strings with a given separator.