Squiggly

Strings

upper, lower, trim, replace, split, join, and friends.

The string builtins. All can be called as a function, a pipe target, or (where the arity allows) a method.

FunctionArityWhat
upper1Uppercase
lower1Lowercase
trim1Strip leading + trailing whitespace
length1Number of characters
len1Alias for length (works on lists / maps too)
isEmpty1True if length is zero
nonEmpty1True if length is non-zero
reverse1Reverse the string
replace3replace s 'old' 'new' — every occurrence
split2split s 'sep' — into a list of strings
join2join list 'sep' — concatenate with separator
startsWith2startsWith s 'prefix'
endsWith2endsWith s 'suffix'
contains2contains s 'needle'
indexOf2indexOf s 'needle'-1 when absent
substring3substring s start end — half-open interval
repeat2repeat s n — repeat the string n times

Examples

{{ .title | upper }}                              CSS HOOK
{{ .author | trim | lower | replace ' ' '-' }}    "ed-maxedon"
{{ .body | split '\n' | length }}                 number of lines

{{ if .filename | endsWith '.md' }}               markdown file
{{ if .body | contains '<!--more-->' }}           has a manual summary cut

{{ split .csv ',' | join ' / ' }}                 reformat