String.PrototypeString.prototype methods
length s returns the UTF-16 length of string s (number of code units). Note: This differs from OCaml's String.length which returns byte count.
to_lower_case s returns a new string with all characters converted to lowercase. Equivalent to JavaScript's String.prototype.toLowerCase().
to_upper_case s returns a new string with all characters converted to uppercase. Equivalent to JavaScript's String.prototype.toUpperCase().
val normalize : normalization -> string -> string optionnormalize form s returns the Unicode Normalization Form of string s. Returns None if normalization fails. Equivalent to JavaScript's String.prototype.normalize().
char_at idx s returns the character at UTF-16 index idx as a string. Returns empty string if index is out of bounds. Equivalent to JavaScript's String.prototype.charAt().
char_code_at idx s returns the UTF-16 code unit at index idx. Returns None if index is out of bounds. Equivalent to JavaScript's String.prototype.charCodeAt().
code_point_at idx s returns the full Unicode code point at UTF-16 index idx. For surrogate pairs, returns the full code point when idx points to the high surrogate. Returns None if index is out of bounds. Equivalent to JavaScript's String.prototype.codePointAt().
slice ~start ~end_ s extracts a section of string. Negative indices count from the end. Equivalent to JavaScript's String.prototype.slice().
substring ~start ~end_ s extracts characters between two indices. Swaps arguments if start > end. Negative values treated as 0. Equivalent to JavaScript's String.prototype.substring().
substring_from start s extracts from start to end of string.
substr ~start ~length s extracts length characters starting from start. Negative start counts from end. Legacy method (Annex B). Equivalent to JavaScript's String.prototype.substr().
index_of search s returns UTF-16 index of first occurrence of search in s. Returns -1 if not found. Equivalent to JavaScript's String.prototype.indexOf().
index_of_from search pos s searches starting from position pos.
last_index_of search s returns UTF-16 index of last occurrence of search in s. Returns -1 if not found. Equivalent to JavaScript's String.prototype.lastIndexOf().
last_index_of_from search pos s searches backwards starting from position pos.
includes search s returns true if s contains search. Equivalent to JavaScript's String.prototype.includes().
includes_from search pos s checks from position pos.
starts_with search s returns true if s starts with search. Equivalent to JavaScript's String.prototype.startsWith().
starts_with_from search pos s checks if s starts with search at position pos.
ends_with search s returns true if s ends with search. Equivalent to JavaScript's String.prototype.endsWith().
ends_with_at search end_pos s checks if s (up to end_pos) ends with search.
trim s removes leading and trailing whitespace. Equivalent to JavaScript's String.prototype.trim().
trim_start s removes leading whitespace. Equivalent to JavaScript's String.prototype.trimStart().
trim_end s removes trailing whitespace. Equivalent to JavaScript's String.prototype.trimEnd().
pad_start target_len s pads s at the start with spaces to reach target_len. Equivalent to JavaScript's String.prototype.padStart().
pad_start_with target_len fill_str s pads s at the start with fill_str.
pad_end target_len s pads s at the end with spaces to reach target_len. Equivalent to JavaScript's String.prototype.padEnd().
pad_end_with target_len fill_str s pads s at the end with fill_str.
match_ pattern s returns captures from first match of pattern in s. Returns None if no match. Equivalent to JavaScript's String.prototype.match().
match_flags pattern flags s matches with specified regex flags.
match_global pattern s returns all matches (with global flag).
val match_all : string -> string -> match_result listmatch_all pattern s returns iterator-like list of all match results. Equivalent to JavaScript's String.prototype.matchAll().
search pattern s returns UTF-16 index of first match, or -1 if not found. Equivalent to JavaScript's String.prototype.search().
search_flags pattern flags s searches with specified regex flags.
replace search replacement s replaces first occurrence of search with replacement. Equivalent to JavaScript's String.prototype.replace() with string argument.
replace_regex pattern replacement s replaces first regex match.
replace_regex_global pattern replacement s replaces all regex matches.
replace_regex_flags pattern flags replacement s replaces with specified flags.
replace_all search replacement s replaces all occurrences. Equivalent to JavaScript's String.prototype.replaceAll().
replace_all_regex pattern replacement s replaces all regex matches.
split separator s splits s by separator. Equivalent to JavaScript's String.prototype.split().
split_limit separator limit s splits with maximum limit parts.