Skip to content
Main site
Standard LibraryM3

UTF-8 Text Processing, Search, Split & Replace

Scalar vs. byte length, all 1,114,112 Unicode code points verified, and text_find/split/replace.

6 min readUpdated: v0.8.0-rc Reference

Bytes vs. Unicode Scalars

length(s) returns UTF-8 byte length, while text_count(s) returns the exact Unicode scalar count. Invalid UTF-8 sequences always produce explicit Result.Err diagnostics.

hadid · EN
let cities = "İstanbul,London,Tokyo";match (text_count(cities)) {    Ok(n) => { print("Scalars: " + json_from_i64(n)); }    Err(e) => { print(e); }}match (text_split(cities, ",")) {    Ok(parts) => {        for (i32 i = 0; i < length(parts); i = i + 1) {            print(parts[i]);        }    }    Err(e) => { print(e); }}match (text_replace("Hadid v0.7", "0.7", "0.8")) {    Ok(updated) => { print(updated); }    Err(e) => { print(e); }}
UTF-8 Text Processing, Search, Split & Replace — HADID