...

Text file src/github.com/go-task/slim-sprig/v3/docs/string_slice.md

Documentation: github.com/go-task/slim-sprig/v3/docs

     1# String Slice Functions
     2
     3These function operate on or generate slices of strings. In Go, a slice is a
     4growable array. In Sprig, it's a special case of a `list`.
     5
     6## join
     7
     8Join a list of strings into a single string, with the given separator.
     9
    10```
    11list "hello" "world" | join "_"
    12```
    13
    14The above will produce `hello_world`
    15
    16`join` will try to convert non-strings to a string value:
    17
    18```
    19list 1 2 3 | join "+"
    20```
    21
    22The above will produce `1+2+3`
    23
    24## splitList and split
    25
    26Split a string into a list of strings:
    27
    28```
    29splitList "$" "foo$bar$baz"
    30```
    31
    32The above will return `[foo bar baz]`
    33
    34The older `split` function splits a string into a `dict`. It is designed to make
    35it easy to use template dot notation for accessing members:
    36
    37```
    38$a := split "$" "foo$bar$baz"
    39```
    40
    41The above produces a map with index keys. `{_0: foo, _1: bar, _2: baz}`
    42
    43```
    44$a._0
    45```
    46
    47The above produces `foo`
    48
    49## splitn
    50
    51`splitn` function splits a string into a `dict`. It is designed to make
    52it easy to use template dot notation for accessing members:
    53
    54```
    55$a := splitn "$" 2 "foo$bar$baz"
    56```
    57
    58The above produces a map with index keys. `{_0: foo, _1: bar$baz}`
    59
    60```
    61$a._0
    62```
    63
    64The above produces `foo`
    65
    66## sortAlpha
    67
    68The `sortAlpha` function sorts a list of strings into alphabetical (lexicographical)
    69order.
    70
    71It does _not_ sort in place, but returns a sorted copy of the list, in keeping
    72with the immutability of lists.

View as plain text