Standard Library: String functions

char


[%char: code]

string?

Prints the Unicode character represented by the Unicode code point code. If code doesn't correspond to a valid character, prints nothing.

Parameters

codeint
The Unicode code point representing the character to print.

lines


[%lines: str]

list

Splits string str by line feed characters (0x0A, \n) and returns a list of the results.

Parameters

strstring
The input string.

lower


[%lower: str]

string

Converts string str to lowercase and returns the result.

Parameters

strstring
The input string.

ord


[%ord: ch]

int?

Prints the Unicode code point of the specified character as an int value. If an empty string is passed, prints nothing.

Parameters

chstring
The input string that provides the character. This can be any length; the function only uses the first code point in the string.

Example

[ord: \s]
# -> 32

ord-all


[%ord-all: str]

list

Prints a list of int values containing the Unicode code points contained in str.

Parameters

strstring
The input string.

Example

# Prints a list of hex values of each code point from the input string
[%as-unicode-hex: str] {
  [cat: **[ord-all: <str>] 
    |> cat: [num-fmt: (:: system = hex; upper = @true)] U\+[] 
    |> tuple
  ]
}

[as-unicode-hex: 👨‍👩‍👦‍👦]
# -> (U+1F468; U+200D; U+1F469; U+200D; U+1F466; U+200D; U+1F466)

split


[%split: str; sep?]

list

Splits the input text by sep into a list of strings. If sep is omitted, splits into characters.

Parameters

strstring
The input string.

sepstring (optional)
The delimiter to split on. If omitted, the string will be split into individual characters.

seg


[%seg: str; size]

list

Segments the input text into a list of strings of size length.

Parameters

strstring
The input string.

sizeint
The size of the segments to produce.

upper


[%upper: str]

string

Converts string str to uppercase and returns the result.