τau /

strings

module
strings = import("strings")

strings - operations on text.

A string is a run of bytes and everything here counts bytes, the way Go does it: Index gives a byte offset, and slicing at one that falls inside a letter outside ASCII cuts the letter in half. The utf8 module is where the code points are.

strings = import("strings")
strings.Split("a,b,c", ",")        # [a, b, c]
strings.Cut("key=value", "=")      # {Before: key, After: value, Found: true}
strings.TrimSpace("  hi\n")        # hi

Nothing is modified in place, since a string cannot be: every function here returns a new one.

Contains = fn(str, sub)source

ContainsAny = fn(str, chars)source

Count = fn(str, sub)source

Cut = fn(str, sub)source

Before = beforevaluesource

After = aftervaluesource

Found = foundvaluesource

HasPrefix = fn(str, pre)source

HasSuffix = fn(str, sub)source

Index = fn(str, sub)source

IndexAny = fn(str, chars)source

Join = fn(arr, sep)source

LastIndex = fn(str, sub)source

LastIndexAny = fn(str, chars)source

Repeat = fn(str, n)source

Reverse = fn(str)source

SplitAfterN = fn(str, sep, n)source

SplitAfter = fn(str, sep)source

SplitN = fn(str, sep, n)source

Split = fn(str, sep)source

Fields = fn(str)source

Fields splits around runs of whitespace, dropping the empty pieces.

TrimPrefix = fn(str, pre)source

TrimSuffix = fn(str, sub)source

ReplaceAll = fn(str, old, new)source

Replace = fn(str, old, new, n)source

ToUpper = fn(str)source

ToLower = fn(str)source

ToTitle = fn(str)source

TrimLeft = fn(str, cutset)source

TrimRight = fn(str, cutset)source

PadLeft = fn(str, width, pad)source

PadLeft returns str padded with pad until it is width long, or str itself if it is already that long. Pad defaults to a space.

PadRight = fn(str, width, pad)source

PadRight is PadLeft, with the padding on the other side.

Trim = fn(str, cutset)source

TrimSpace = fn(str)source