Tanguv0.35.0
Text & i18n26 exports
Raw Markdown

/string

UTF-8 string utilities for case conversion, trimming, padding, searching, and slugification.

(use /string)

Functions & symbols#

byte-count-of#

function
(string/byte-count-of s) -> Int

Returns the raw UTF-8 byte length of `s` in O(1) time.

ParameterTypeOptionalDescription
sStringrequiredUTF-8 string
Returns:Any
(string/byte-count-of "café") ; -> 5

byte-slice#

function
(string/byte-slice s start [end]) -> String

Slices `s` by UTF-8 byte offsets in O(1) time (verifying character boundaries).

ParameterTypeOptionalDescription
sStringrequiredSource UTF-8 string
startIntrequiredStart byte offset
endIntoptionalOptional exclusive end byte offset
Returns:Any
(string/byte-slice "hello" 0 4)

chars#

function
(chars str) -> Array

Converts string into an array of individual Unicode Char elements.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any
(chars "tan") ; -> ['t' 'a' 'n']

contains?#

function
(contains? str substring) -> Bool

Returns true if str contains the given substring.

ParameterTypeOptionalDescription
strStringrequiredHaystack
substringStringrequiredNeedle
Returns:Any
(contains? "hello world" "world") ; -> true

count-of#

function
(string/count-of s) -> Int

Returns the number of Unicode characters (code points) in `s`.

ParameterTypeOptionalDescription
sStringrequiredUTF-8 string
Returns:Any
(string/count-of "café") ; -> 4

ends-with?#

function
(ends-with? str suffix) -> Bool

Returns true if str ends with suffix.

ParameterTypeOptionalDescription
strStringrequiredInput string
suffixStringrequiredSuffix to check
Returns:Any
(ends-with? "main.tan" ".tan") ; -> true

format-string#

function
(string/format-string template args...) -> String

Formats a template string with positional argument substitution.

ParameterTypeOptionalDescription
templateStringrequiredTemplate format string
argsAnyrequiredValues to format into placeholders
Returns:Any
(string/format-string "Hello {}!" "Tangu")

ignore-case-contains?#

function
(string/ignore-case-contains? str substring) -> Bool

Returns true if str contains the given substring (case-insensitive, zero-allocation for ASCII).

ParameterTypeOptionalDescription
strStringrequiredHaystack
substringStringrequiredNeedle
Returns:Any
(use {ignore-case-contains?} /string)
(ignore-case-contains? "TikTok.com" "tiktok.com") ; -> true

ignore-case-index-of#

function
(string/ignore-case-index-of str sub) -> (Or Int)

Returns 0-based character index of substring `sub` in `str` (case-insensitive), or () if not found.

ParameterTypeOptionalDescription
strStringrequiredHaystack
subStringrequiredNeedle
from-indexIntrequiredOptional 0-based start character index
Returns:Any
(use {ignore-case-index-of} /string)
(ignore-case-index-of "Hello World" "world") ; -> 6

index-of#

function
(string/index-of s needle) -> (Or Int None)

Returns the 0-based character index of the first occurrence of `needle`, or `()` if absent.

ParameterTypeOptionalDescription
sStringrequiredHaystack string
needleStringrequiredSubstring to locate
Returns:Any
(string/index-of "tangu.dev" ".") ; -> 5

is-blank?#

function
(string/is-blank? x) -> Bool

Returns true if x is (), "", or contains only whitespace characters.

ParameterTypeOptionalDescription
xAnyrequiredValue to check (String or None)
Returns:Any
(use {is-blank?} /string)
(is-blank? "   ") ; -> true

last-index-of#

function
(string/last-index-of str sub) -> (Or Int)

Returns last 0-based character index of substring `sub` in `str` (optionally up to `end-index`), or () if not found.

ParameterTypeOptionalDescription
strStringrequiredHaystack
subStringrequiredNeedle
end-indexIntrequiredOptional 0-based end character index
Returns:Any
(use {last-index-of} /string)
(last-index-of "hello world" "o") ; -> 7

pad-left#

function
(pad-left str width) -> String

Pads string on the left with spaces until it reaches width.

ParameterTypeOptionalDescription
strStringrequiredString to pad
widthIntrequiredTarget total width
Returns:Any
(pad-left "42" 5) ; -> "   42"

pad-right#

function
(pad-right str width) -> String

Pads string on the right with spaces until it reaches width.

ParameterTypeOptionalDescription
strStringrequiredString to pad
widthIntrequiredTarget total width
Returns:Any
(pad-right "42" 5) ; -> "42   "

repeat#

function
(string/repeat s count) -> String

Repeats `s` `count` times consecutively.

ParameterTypeOptionalDescription
sStringrequiredString to repeat
countIntrequiredRepetition count >= 0
Returns:Any
(string/repeat "ab" 3) ; -> "ababab"

replace#

function
(replace str from to) -> String

Replaces all occurrences of `from` with `to` in `str`.

ParameterTypeOptionalDescription
strStringrequiredTarget string
fromStringrequiredSubstring to find
toStringrequiredReplacement string
Returns:Any
(replace "foo bar" "bar" "baz") ; -> "foo baz"

slice#

function
(slice str start) -> String

Returns substring from start to end index. Supports negative indices and Range literals like (slice str 0..5).

ParameterTypeOptionalDescription
strStringrequiredInput string
startIntrequired0-based start index (supports negative bounds)
endIntrequiredOptional exclusive end index
Returns:Any
(slice "hello" 0 2) ; -> "he"

split#

function
(split str delimiter) -> Array

Splits str by separator delimiter, returning an Array of substrings.

ParameterTypeOptionalDescription
strStringrequiredString to split
delimiterStringrequiredSeparator
Returns:Any
(split "a,b,c" ",") ; -> ["a" "b" "c"]

starts-with?#

function
(starts-with? str prefix) -> Bool

Returns true if str begins with prefix.

ParameterTypeOptionalDescription
strStringrequiredInput string
prefixStringrequiredPrefix to check
Returns:Any
(starts-with? "/api/users" "/api") ; -> true

strip-prefix#

function
(string/strip-prefix s prefix) -> String

Removes `prefix` from the start of `s` when present, leaving `s` unchanged otherwise.

ParameterTypeOptionalDescription
sStringrequiredInput string
prefixStringrequiredPrefix to strip if present
Returns:Any
(string/strip-prefix "/stdlib" "/") ; -> "stdlib"

strip-suffix#

function
(string/strip-suffix s suffix) -> String

Removes `suffix` from the end of `s` when present, leaving `s` unchanged otherwise.

ParameterTypeOptionalDescription
sStringrequiredInput string
suffixStringrequiredSuffix to strip if present
Returns:Any
(string/strip-suffix "file.tan" ".tan") ; -> "file"

to-lower-case#

function
(to-lower-case str) -> String

Converts all characters in string to lowercase.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any
(to-lower-case "TANGU") ; -> "tangu"

to-upper-case#

function
(to-upper-case str) -> String

Converts all characters in string to uppercase.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any
(to-upper-case "tangu") ; -> "TANGU"

trim#

function
(trim str) -> String

Returns a copy of the string with leading and trailing whitespace removed.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any
(trim "  hello  ") ; -> "hello"

trim-end#

function
(trim-end str) -> String

Returns string with trailing whitespace removed.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any

trim-start#

function
(trim-start str) -> String

Returns string with leading whitespace removed.

ParameterTypeOptionalDescription
strStringrequiredInput string
Returns:Any