string
Extra string utilities beyond the built-in string methods.
Import
import stringFunctions
string.pad_left(s: str, n: int, ch?: str) -> str
Left-pad string to total width n, using ch (default space).
string.pad_right(s: str, n: int, ch?: str) -> str
Right-pad string to total width n.
string.center(s: str, n: int, ch?: str) -> str
Center string in a field of width n.
string.truncate(s: str, n: int, suffix?: str) -> str
Truncate string to total length n, appending suffix if truncated.
string.camel_to_snake(s: str) -> str
Convert helloWorld to hello_world.
string.snake_to_camel(s: str) -> str
Convert hello_world to helloWorld.
string.escape_html(s: str) -> str
Escape HTML special characters (< > & ").
string.is_numeric(s: str) -> bool
True if the string represents a valid number.
string.words(s: str) -> [str]
Split string into words on whitespace.
string.levenshtein(a: str, b: str) -> int
Edit distance between two strings.
string.similarity(a: str, b: str) -> float
Similarity score from 0.0 to 1.0 based on edit distance.
string.repeat(s: str, n: int) -> str
Repeat string n times.
string.chars(s: str) -> [str]
Split string into an array of single characters.
string.bytes(s: str) -> [int]
Convert string to an array of byte values.
Examples
scratch.xs