strings
String inspection, search, and transformation for general text work. Covers length and character-class predicates, case conversion, find/contains/split/join, trim, replace, pad, runtime `format` templates, and escape helpers for HTML, shell, JSON, and regex. CX strings are UTF-8 and most operations are Unicode-aware: indexing, length, and slicing are codepoint-positioned, case folding follows Unicode tables, and predicates use Unicode categories. For byte-level work see cx-stdlib/bytes; for regex see cx-stdlib/re.
strings:length
[$strings:length] -> int — Count the codepoints (Unicode scalar values) in a string.
[?lib 'cx-stdlib/strings']
[$strings:length "héllo"]
5
strings:length-bytes
[$strings:length-bytes] -> int — Count the UTF-8 bytes in a string.
[?lib 'cx-stdlib/strings']
[$strings:length-bytes "héllo"]
6
strings:is-empty
[$strings:is-empty] -> bool — Report whether a string has zero length.
[?lib 'cx-stdlib/strings']
[$strings:is-empty ""]
true
strings:at
[$strings:at] -> string — Return the single-character substring at a codepoint position; raises if out of bounds.
[?lib 'cx-stdlib/strings']
[$strings:at "héllo" 1]
'é'
strings:slice
[$strings:slice] -> string — Extract a half-open substring by codepoint range; bounds are clamped.
[?lib 'cx-stdlib/strings']
[$strings:slice "héllo" 1 4]
'éll'
strings:reverse
[$strings:reverse] -> string — Reverse a string by codepoint.
[?lib 'cx-stdlib/strings']
[$strings:reverse "héllo"]
'olléh'
strings:contains
[$strings:contains] -> bool — Report whether a string contains the given substring.
[?lib 'cx-stdlib/strings']
[$strings:contains "foobar" "oba"]
true
strings:find
[$strings:find] -> int — Return the codepoint index of the first occurrence of a substring, or -1 if absent.
[?lib 'cx-stdlib/strings']
[$strings:find "héllo" "llo"]
2
strings:find-from
[$strings:find-from] -> int — Find the first occurrence of a substring at or after a starting index, or -1 if absent.
[?lib 'cx-stdlib/strings']
[$strings:find-from "abcabc" "bc" 2]
4
strings:rfind
[$strings:rfind] -> int — Return the codepoint index of the last (right-to-left) occurrence of a substring, or -1 if absent.
[?lib 'cx-stdlib/strings']
[$strings:rfind "abcabc" "bc"]
4
strings:starts-with
[$strings:starts-with] -> bool — Report whether a string begins with the given prefix.
[?lib 'cx-stdlib/strings']
[$strings:starts-with "foobar" "foo"]
true
strings:ends-with
[$strings:ends-with] -> bool — Report whether a string ends with the given suffix.
[?lib 'cx-stdlib/strings']
[$strings:ends-with "foobar" "bar"]
true
strings:count
[$strings:count] -> int — Count non-overlapping occurrences of a substring.
[?lib 'cx-stdlib/strings']
[$strings:count "aaaa" "aa"]
2
strings:find-all
[$strings:find-all] -> [sequence int] — Return the codepoint indices of every non-overlapping occurrence of a substring.
[?lib 'cx-stdlib/strings']
[$strings:find-all "abcabc" "bc"]
(1, 4)
strings:upper
[$strings:upper] -> string — Upper-case a string using Unicode default case tables (locale-independent).
[?lib 'cx-stdlib/strings']
[$strings:upper "hello"]
'HELLO'
strings:lower
[$strings:lower] -> string — Lower-case a string using Unicode default case tables (locale-independent).
[?lib 'cx-stdlib/strings']
[$strings:lower "HeLLo"]
'hello'
strings:title
[$strings:title] -> string — Title-case a string at Unicode UAX #29 word boundaries.
[?lib 'cx-stdlib/strings']
[$strings:title "jean-paul sartre"]
'Jean-Paul Sartre'
strings:case-fold
[$strings:case-fold] -> string — Produce the canonical case-folded form for case-insensitive comparison.
[?lib 'cx-stdlib/strings']
[$strings:case-fold "STRAßE"]
'strasse'
strings:swap-case
[$strings:swap-case] -> string — Swap the case of each cased character, upper to lower and lower to upper.
[?lib 'cx-stdlib/strings']
[$strings:swap-case "Hello World"]
'hELLO wORLD'
strings:upper-locale
[$strings:upper-locale] -> string — Upper-case a string with locale-aware rules (e.g. Turkish dotted-i).
[?lib 'cx-stdlib/strings']
[$strings:upper-locale "abc" "en"]
'ABC'
strings:lower-locale
[$strings:lower-locale] -> string — Lower-case a string with locale-aware rules (e.g. Turkish dotted-i).
[?lib 'cx-stdlib/strings']
[$strings:lower-locale "ABC" "en"]
'abc'
strings:trim
[$strings:trim] -> string — Strip Unicode whitespace from both ends of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim " hi "]
'hi'
strings:trim-start
[$strings:trim-start] -> string — Strip Unicode whitespace from the start of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim-start " hi "]
'hi '
strings:trim-end
[$strings:trim-end] -> string — Strip Unicode whitespace from the end of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim-end " hi "]
' hi'
strings:trim-chars
[$strings:trim-chars] -> string — Strip any of the given characters from both ends of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim-chars "<>" ""]
'hi'
strings:trim-start-chars
[$strings:trim-start-chars] -> string — Strip any of the given characters from the start of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim-start-chars "xxhi" "x"]
'hi'
strings:trim-end-chars
[$strings:trim-end-chars] -> string — Strip any of the given characters from the end of a string.
[?lib 'cx-stdlib/strings']
[$strings:trim-end-chars "hixx" "x"]
'hi'
strings:split
[$strings:split] -> [sequence string] — Split a string on each occurrence of a separator; empty separator splits every character.
[?lib 'cx-stdlib/strings']
[$strings:split "a,b,c" ","]
('a', 'b', 'c')
strings:split-limit
[$strings:split-limit] -> [sequence string] — Split a string on a separator into at most max+1 segments.
[?lib 'cx-stdlib/strings']
[$strings:split-limit "a,b,c,d" "," 2]
('a', 'b', 'c,d')
strings:split-lines
[$strings:split-lines] -> [sequence string] — Split a string into lines on LF, CRLF, or CR; a trailing empty line is dropped.
[?lib 'cx-stdlib/strings']
[$strings:split-lines "a\nb\r\nc\rd"]
('a', 'b', 'c', 'd')
strings:split-whitespace
[$strings:split-whitespace] -> [sequence string] — Split a string on runs of Unicode whitespace, collapsing consecutive whitespace.
[?lib 'cx-stdlib/strings']
[$strings:split-whitespace " a b \t c "]
('a', 'b', 'c')
strings:join
[$strings:join] -> string — Concatenate a sequence of strings, inserting the separator between each.
[?lib 'cx-stdlib/strings']
[$strings:join ("a", "b", "c") "-"]
'a-b-c'
strings:replace
[$strings:replace] -> string — Replace every occurrence of a substring with another.
[?lib 'cx-stdlib/strings']
[$strings:replace "a.b.c" "." "-"]
'a-b-c'
strings:replace-first
[$strings:replace-first] -> string — Replace only the first occurrence of a substring with another.
[?lib 'cx-stdlib/strings']
[$strings:replace-first "a.b.c" "." "-"]
'a-b.c'
strings:replace-n
[$strings:replace-n] -> string — Replace at most the first n occurrences of a substring with another.
[?lib 'cx-stdlib/strings']
[$strings:replace-n "a.b.c.d" "." "-" 2]
'a-b-c.d'
strings:replace-exactly
[$strings:replace-exactly] -> string — Fail-loud surgical replace: `from` MUST occur exactly once, else an [err cx-err:CXER2903] value (no silent no-op on a miss, no over-replace on ambiguity). The safety the harness Edit tool gives, for in-CX text edits.
[?lib 'cx-stdlib/strings']
[$strings:replace-exactly "a.b.c" "b" "X"]
'a.X.c'
strings:pad-start
[$strings:pad-start] -> string — Left-pad a string with a fill string until it reaches the target width.
[?lib 'cx-stdlib/strings']
[$strings:pad-start "abc" 10 "0"]
'0000000abc'
strings:pad-end
[$strings:pad-end] -> string — Right-pad a string with a fill string until it reaches the target width.
[?lib 'cx-stdlib/strings']
[$strings:pad-end "abc" 6 "."]
'abc...'
strings:center
[$strings:center] -> string — Center a string within the target width, padding both sides with a fill string.
[?lib 'cx-stdlib/strings']
[$strings:center "hi" 6 "*"]
'**hi**'
strings:repeat
[$strings:repeat] -> string — Concatenate n copies of a string.
[?lib 'cx-stdlib/strings']
[$strings:repeat "ab" 3]
'ababab'
strings:is-ascii
[$strings:is-ascii] -> bool — Report whether every character is ASCII (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-ascii "hello"]
true
strings:is-digit
[$strings:is-digit] -> bool — Report whether every character is a Unicode digit (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-digit "12345"]
true
strings:is-alpha
[$strings:is-alpha] -> bool — Report whether every character is a Unicode letter (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-alpha "abcDEF"]
true
strings:is-alphanumeric
[$strings:is-alphanumeric] -> bool — Report whether every character is a Unicode letter or digit (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-alphanumeric "abc123"]
true
strings:is-whitespace
[$strings:is-whitespace] -> bool — Report whether every character is Unicode whitespace (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-whitespace " \t\n"]
true
strings:is-upper
[$strings:is-upper] -> bool — Report whether every cased character is upper-case (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-upper "ABC"]
true
strings:is-lower
[$strings:is-lower] -> bool — Report whether every cased character is lower-case (empty string is true).
[?lib 'cx-stdlib/strings']
[$strings:is-lower "abc"]
true
strings:is-blank
[$strings:is-blank] -> bool — Report whether a string is empty or contains only whitespace.
[?lib 'cx-stdlib/strings']
[$strings:is-blank " "]
true
strings:format
[$strings:format] -> string — Substitute positional and named placeholders in a template with the given args.
[?lib 'cx-stdlib/strings']
[$strings:format "Hello, {}! You have {} messages." ("Alice", 5)]
'Hello, Alice! You have 5 messages.'
strings:escape-html
[$strings:escape-html] -> string — Escape the five HTML metacharacters & < > double-quote and single-quote.
[?lib 'cx-stdlib/strings']
[$strings:escape-html "&'"]
'<a href="x">&''
strings:unescape-html
[$strings:unescape-html] -> string — Decode numeric and HTML5 named character references back to text.
[?lib 'cx-stdlib/strings']
[$strings:unescape-html "a…b—c©"]
'a…b—c©'
strings:escape-shell
[$strings:escape-shell] -> string — Quote a string for safe use as a single POSIX shell argument.
strings:escape-json
[$strings:escape-json] -> string — Apply JSON string escapes to a string.
[?lib 'cx-stdlib/strings']
[$strings:escape-json "a\"b"]
'a\\"b'
strings:escape-regex
[$strings:escape-regex] -> string — Escape regex metacharacters so a string matches literally.
[?lib 'cx-stdlib/strings']
[$strings:escape-regex "a.b*c"]
'a\.b\*c'
strings:to-number
[$strings:to-number] -> [or number absence] — Parse a locale-free numeric string into a number — int for pure-integer syntax, float for fractional / exponent syntax. Surrounding whitespace is trimmed; a non-numeric input (trailing junk, grouping separators, empty) yields the absence channel () rather than a silent string passthrough, so callers branch with [?else]. For grouping / Unicode digits use cx-stdlib/locale.
[?lib 'cx-stdlib/strings']
[$strings:to-number "3.07"]
3.07
strings:to-int
[$strings:to-int] -> [or int absence] — Parse a locale-free integer string (optional sign, ASCII digits) into an int; fractional or exponent syntax ("3.07", "1e3") and non-numeric input yield the absence channel ().
[?lib 'cx-stdlib/strings']
[$strings:to-int "42"]
42
strings:to-float
[$strings:to-float] -> [or float absence] — Parse any locale-free numeric string into a float ("5" -> 5.0); a non-numeric input yields the absence channel ().
[?lib 'cx-stdlib/strings']
[$strings:to-float "5"]
5.0