By Andrew Owen
Released under the MIT license


Various string-related functions

str-concat ( str-a str-b -- str-ab )

Concatenate str-a and str-b, allocating a new string

>string ( anyVal -- str )

Cast the top value of the stack to a string.

str>int ( str -- int! )

Attempt to parse a string from the top of the stack into an int.

str-join ( vec sep -- str )

Casts each element of vec to a string, and then joins them with sep in the middle

str-ends? ( str endstr -- endswith? )

Checks to see if str ends with endstr

str-eq? ( a b -- eq? )

Compares two strings for equality.

str-substr ( str start end -- substr )

Takes a substring of str over the range [start:end]

str-idx-of ( str sub -- idx )

Find the index of the first instance of sub in str

str-split ( str sep -- vec )

Split str into a vector of strings, based on sep

str-starts? ( str prefix -- startswith? )

Check to see if str starts with prefix.

str-empty? ( str -- empty? )

Returns true if the string has a length of 0 or less

str>rune-reader ( str -- reader )

Creates a rune-reader from str

each-char ( str quot -- .. )

Executes quot for each character in str

str-replace ( str pat replace -- .. )

Returns a new string based on str with `pat` swapped for `replace`

str-contains? ( str cont -- contained? )

Returns true if `cont` is in str, false otherwise

str-count ( str:string char:string -- numOccurs:int )

Count the number of times that char occures in str

str-repeat ( str repeat-count -- 'str )

Returns a new string that is str repeated `repeat-count` times

str-trim ( str -- 'str )

Trims whitespace off the front and back of `str`

str-upper ( str -- upper-str )

Returns an upper-cased copy of str

str-lower ( str -- lower-str )

Returns an lower-cased copy of str

str-reverse ( str -- reversed-runes )

Splits a string into runes, and then reverses the runes into a new string

str-reverse-bytes ( str -- reversed-bytes )

Splits a string into bytes, and then reverses the bytes into a new string

str-reverse-graphemes ( str -- reversed-graphemes )

Reverses str by grapheme clusters

str-count ( str:string char:string -- numOccurs:int )

Count the number of times that char occures in str

str? ( obj:any -- isStr?:bool )

Is this stack value a string?

str-neq? ( str-a str-b -- eq? )

Are these two strings not equal?