GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • View on GitHub

This view

  • Original page
  • New address

GeezerVison is showing masterminds.github.io — String Slice Functions

String Slice 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. 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.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.