Janet 1.1.0-dev Documentation

String Module

Index

string/ascii-lower string/ascii-upper string/bytes string/check-set string/find string/find-all string/format string/from-bytes string/has-prefix? string/has-suffix? string/join string/repeat string/replace string/replace-all string/reverse string/slice string/split string/trim string/triml string/trimr


string/ascii-lower cfunction
(string/ascii-lower str)

Returns a new string where all bytes are replaced with the lowercase version of themselves in ASCII. Does only a very simple case check, meaning no unicode support.

string/ascii-upper cfunction
(string/ascii-upper str)

Returns a new string where all bytes are replaced with the uppercase version of themselves in ASCII. Does only a very simple case check, meaning no unicode support.

string/bytes cfunction
(string/bytes str)

Returns an array of integers that are the byte values of the string.

string/check-set cfunction
(string/check-set set str)

Checks if any of the bytes in the string set appear in the string str. Returns true if some bytes in set do appear in str, false if no bytes do.

string/find cfunction
(string/find patt str)

Searches for the first instance of pattern patt in string str. Returns the index of the first character in patt if found, otherwise returns nil.

string/find-all cfunction
(string/find patt str)

Searches for all instances of pattern patt in string str. Returns an array of all indices of found patterns. Overlapping instances of the pattern are not counted, meaning a byte in string will only contribute to finding at most on occurrence of pattern. If no occurrences are found, will return an empty array.

string/format cfunction
(string/format format & values)

Similar to snprintf, but specialized for operating with janet. Returns a new string.

string/from-bytes cfunction
(string/from-bytes & byte-vals)

Creates a string from integer params with byte values. All integers will be coerced to the range of 1 byte 0-255.

string/has-prefix? cfunction
(string/has-prefix? pfx str)

Tests whether str starts with pfx.

string/has-suffix? cfunction
(string/has-suffix? sfx str)

Tests whether str ends with sfx.

string/join cfunction
(string/join parts &opt sep)

Joins an array of strings into one string, optionally separated by a separator string sep.

string/repeat cfunction
(string/repeat bytes n)

Returns a string that is n copies of bytes concatenated.

string/replace cfunction
(string/replace patt subst str)

Replace the first occurrence of patt with subst in the string str. Will return the new string if patt is found, otherwise returns str.

string/replace-all cfunction
(string/replace-all patt subst str)

Replace all instances of patt with subst in the string str. Will return the new string if patt is found, otherwise returns str.

string/reverse cfunction
(string/reverse str)

Returns a string that is the reversed version of str.

string/slice cfunction
(string/slice bytes &opt start end)

Returns a substring from a byte sequence. The substring is from index start inclusive to index end exclusive. All indexing is from 0. 'start' and 'end' can also be negative to indicate indexing from the end of the string.

string/split cfunction
(string/split delim str)

Splits a string str with delimiter delim and returns an array of substrings. The substrings will not contain the delimiter delim. If delim is not found, the returned array will have one element.

string/trim cfunction
(string/trim str &opt set)

Trim leading and trailing whitespace from a byte sequence. If the argument set is provided, consider only characters in set to be whitespace.

string/triml cfunction
(string/triml str &opt set)

Trim leading whitespace from a byte sequence. If the argument set is provided, consider only characters in set to be whitespace.

string/trimr cfunction
(string/trimr str &opt set)

Trim trailing whitespace from a byte sequence. If the argument set is provided, consider only characters in set to be whitespace.