The string module contains a lot of useful commands to work with strings.
If you want to join several values from a list into a single string you can use the str join command.
The command accepts as argument the character(s) to use for joining the values.
If you don't specify the character(s) as argument the default value '' (empty string) is used.
In the following example you can see usages of the str join command with and without extra arguments:
use std/assert # Using str join without argument. assert equal (['a' 'b' 'c'] | str join) 'abc' # str join can be used with an argument to specify # the character(s) used for joining the values. assert equal (['a' 'b' 'c'] | str join ', ') 'a, b, c' assert equal (['a' 'b' 'c'] | str join ':') 'a:b:c' assert equal ([1 2 3] | str join ' x ') '1 x 2 x 3' # '' is the default join character, but you can set # it explicitly as well. assert equal (['a' 'b' 'c'] | str join '') 'abc'
Written with Nushell 0.108.0.