soma.cell

String builtins

String builtins, in the reference of the Soma programming language (soma 3.2.4). A block marked ✓ is a whole program that soma check accepts; the others are excerpts.

len("hello")                    // 5 (chars, not bytes)
concat("foo", "bar")            // "foobar"
contains("hello", "ell")        // true
starts_with("hello", "he")      // true
ends_with("hello.txt", ".txt")  // true
replace("hello", "l", "r")     // "herro"
split("a,b,c", ",")            // ["a", "b", "c"]
trim("  hi  ")                  // "hi"
uppercase("hello")              // "HELLO"
lowercase("HELLO")              // "hello"
substring("hello", 1, 3)        // "el"
index_of("hello", "ll")         // 2
escape_html("<b>x</b>")         // "&lt;b&gt;x&lt;/b&gt;"
to_json(map("a", 1))            // {"a":1}  (compact, like JSON.stringify; print(m) shows {"a": 1})
from_json("{\"a\": 1}")         // map