1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-11-29 11:50:22 +01:00
ntfy/docs/sprig/string_slice.md
2025-07-07 22:23:32 -06:00

1.4 KiB

String List Functions

These function operate on or generate slices of strings. In Go, a slice is a growable array. In Sprig, it's a special case of a list.

join

Join a list of strings into a single string, with the given separator.

list "hello" "world" | join "_"

The above will produce hello_world

join will try to convert non-strings to a string value:

list 1 2 3 | join "+"

The above will produce 1+2+3

splitList and split

Split a string into a list of strings:

splitList "$" "foo$bar$baz"

The above will return [foo bar baz]

The older split function splits a string into a dict. It is designed to make it easy to use template dot notation for accessing members:

$a := split "$" "foo$bar$baz"

The above produces a map with index keys. {_0: foo, _1: bar, _2: baz}

$a._0

The above produces foo

splitn

splitn function splits a string into a dict with n keys. It is designed to make it easy to use template dot notation for accessing members:

$a := splitn "$" 2 "foo$bar$baz"

The above produces a map with index keys. {_0: foo, _1: bar$baz}

$a._0

The above produces foo

sortAlpha

The sortAlpha function sorts a list of strings into alphabetical (lexicographical) order.

It does not sort in place, but returns a sorted copy of the list, in keeping with the immutability of lists.