diff options
| author | Karl Schriek <kschriek@gmail.com> | 2022-01-10 03:24:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-09 20:24:34 -0500 |
| commit | 21664a8ffb37ec83bfb8f717ef723c503eed6e5a (patch) | |
| tree | 3c0bf361e287b4b75fa61fde67bbdf8aabd8630f /docs | |
| parent | 155803de7d5c1df5edd456a45a19008c9ae5ea7b (diff) | |
Add strings.Split example to strings.md (#1279)
Add additional examples to clarifiy typical use cases for strings.Split.
Resolves https://github.com/hairyhenderson/gomplate/issues/1278
Co-authored-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/content/functions/strings.md | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/content/functions/strings.md b/docs/content/functions/strings.md index a3830771..65b4193c 100644 --- a/docs/content/functions/strings.md +++ b/docs/content/functions/strings.md @@ -229,6 +229,13 @@ input | strings.Split separator ### Examples +Use on its own to produce an array: +```console +$ gomplate -i '{{ "Bart,Lisa,Maggie" | strings.Split "," }}' +[Bart Lisa Maggie] +``` + +Use in combination with `range` to iterate over all items: ```console $ gomplate -i '{{range ("Bart,Lisa,Maggie" | strings.Split ",") }}Hello, {{.}} {{end}}' @@ -237,6 +244,13 @@ Hello, Lisa Hello, Maggie ``` +Use in combination with `index` function to pick a specific value from the resulting array +```console +$ gomplate -i '{{index ("Bart,Lisa,Maggie" | strings.Split ",") 0 }}' +Bart +``` + + ## `strings.SplitN` Creates a slice by splitting a string on a given delimiter. The count determines |
