/string
UTF-8 string utilities for case conversion, trimming, padding, searching, and slugification.
Functions & symbols#
byte-count-of#
Returns the raw UTF-8 byte length of `s` in O(1) time.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | UTF-8 string |
Any(string/byte-count-of "café") ; -> 5byte-slice#
Slices `s` by UTF-8 byte offsets in O(1) time (verifying character boundaries).
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | Source UTF-8 string |
start | Int | required | Start byte offset |
end | Int | optional | Optional exclusive end byte offset |
Any(string/byte-slice "hello" 0 4)chars#
Converts string into an array of individual Unicode Char elements.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Any(chars "tan") ; -> ['t' 'a' 'n']contains?#
Returns true if str contains the given substring.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Haystack |
substring | String | required | Needle |
Any(contains? "hello world" "world") ; -> truecount-of#
Returns the number of Unicode characters (code points) in `s`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | UTF-8 string |
Any(string/count-of "café") ; -> 4ends-with?#
Returns true if str ends with suffix.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
suffix | String | required | Suffix to check |
Any(ends-with? "main.tan" ".tan") ; -> trueformat-string#
Formats a template string with positional argument substitution.
| Parameter | Type | Optional | Description |
|---|---|---|---|
template | String | required | Template format string |
args | Any | required | Values to format into placeholders |
Any(string/format-string "Hello {}!" "Tangu")ignore-case-contains?#
Returns true if str contains the given substring (case-insensitive, zero-allocation for ASCII).
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Haystack |
substring | String | required | Needle |
Any(use {ignore-case-contains?} /string)
(ignore-case-contains? "TikTok.com" "tiktok.com") ; -> trueignore-case-index-of#
Returns 0-based character index of substring `sub` in `str` (case-insensitive), or () if not found.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Haystack |
sub | String | required | Needle |
from-index | Int | required | Optional 0-based start character index |
Any(use {ignore-case-index-of} /string)
(ignore-case-index-of "Hello World" "world") ; -> 6index-of#
Returns the 0-based character index of the first occurrence of `needle`, or `()` if absent.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | Haystack string |
needle | String | required | Substring to locate |
Any(string/index-of "tangu.dev" ".") ; -> 5is-blank?#
Returns true if x is (), "", or contains only whitespace characters.
| Parameter | Type | Optional | Description |
|---|---|---|---|
x | Any | required | Value to check (String or None) |
Any(use {is-blank?} /string)
(is-blank? " ") ; -> truelast-index-of#
Returns last 0-based character index of substring `sub` in `str` (optionally up to `end-index`), or () if not found.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Haystack |
sub | String | required | Needle |
end-index | Int | required | Optional 0-based end character index |
Any(use {last-index-of} /string)
(last-index-of "hello world" "o") ; -> 7pad-left#
Pads string on the left with spaces until it reaches width.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | String to pad |
width | Int | required | Target total width |
Any(pad-left "42" 5) ; -> " 42"pad-right#
Pads string on the right with spaces until it reaches width.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | String to pad |
width | Int | required | Target total width |
Any(pad-right "42" 5) ; -> "42 "repeat#
Repeats `s` `count` times consecutively.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | String to repeat |
count | Int | required | Repetition count >= 0 |
Any(string/repeat "ab" 3) ; -> "ababab"replace#
Replaces all occurrences of `from` with `to` in `str`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Target string |
from | String | required | Substring to find |
to | String | required | Replacement string |
Any(replace "foo bar" "bar" "baz") ; -> "foo baz"slice#
Returns substring from start to end index. Supports negative indices and Range literals like (slice str 0..5).
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
start | Int | required | 0-based start index (supports negative bounds) |
end | Int | required | Optional exclusive end index |
Any(slice "hello" 0 2) ; -> "he"split#
Splits str by separator delimiter, returning an Array of substrings.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | String to split |
delimiter | String | required | Separator |
Any(split "a,b,c" ",") ; -> ["a" "b" "c"]starts-with?#
Returns true if str begins with prefix.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
prefix | String | required | Prefix to check |
Any(starts-with? "/api/users" "/api") ; -> truestrip-prefix#
Removes `prefix` from the start of `s` when present, leaving `s` unchanged otherwise.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | Input string |
prefix | String | required | Prefix to strip if present |
Any(string/strip-prefix "/stdlib" "/") ; -> "stdlib"strip-suffix#
Removes `suffix` from the end of `s` when present, leaving `s` unchanged otherwise.
| Parameter | Type | Optional | Description |
|---|---|---|---|
s | String | required | Input string |
suffix | String | required | Suffix to strip if present |
Any(string/strip-suffix "file.tan" ".tan") ; -> "file"to-lower-case#
Converts all characters in string to lowercase.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Any(to-lower-case "TANGU") ; -> "tangu"to-upper-case#
Converts all characters in string to uppercase.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Any(to-upper-case "tangu") ; -> "TANGU"trim#
Returns a copy of the string with leading and trailing whitespace removed.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Any(trim " hello ") ; -> "hello"trim-end#
Returns string with trailing whitespace removed.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Anytrim-start#
Returns string with leading whitespace removed.
| Parameter | Type | Optional | Description |
|---|---|---|---|
str | String | required | Input string |
Any