Skip to content

std.string

std.string

std.string is the current text-processing module. It also carries the conversion helpers that other languages might place in a dedicated fmt or convert package.

Import

import std.string as string

Reference

NameSignatureDescription
str_eqfunc str_eq(left: str, right: str) -> boolstring equality
concatfunc concat(left: str, right: str) -> strconcatenate two strings
splitfunc split(value: str, sep: str) -> Array[str]split into array
trimfunc trim(value: str) -> strtrim whitespace
from_intfunc from_int(value: i32) -> strformat i32
to_intfunc to_int(value: str) -> i32parse i32
lenfunc len(value: str) -> i32byte length
slenfunc slen(value: str) -> i32alias of len
containsfunc contains(value: str, sub: str) -> boolsubstring test
starts_withfunc starts_with(value: str, prefix: str) -> boolprefix test
ends_withfunc ends_with(value: str, suffix: str) -> boolsuffix test
findfunc find(value: str, sub: str) -> i32first index or -1
replacefunc replace(value: str, old_value: str, new_value: str) -> strreplace all
to_upperfunc to_upper(value: str) -> struppercase
to_lowerfunc to_lower(value: str) -> strlowercase
pad_leftfunc pad_left(value: str, width: i32, ch: str) -> strleft pad
pad_rightfunc pad_right(value: str, width: i32, ch: str) -> strright pad
repeatfunc repeat(value: str, count: i32) -> strrepeat
reversefunc reverse(value: str) -> strreverse byte-wise
stripfunc strip(value: str, chars: str) -> strstrip edge chars
char_atfunc char_at(value: str, index: i32) -> strsingle-character string
to_f64func to_f64(value: str) -> f64parse f64
from_f64func from_f64(value: f64) -> strformat f64
from_boolfunc from_bool(value: bool) -> strformat bool
to_boolfunc to_bool(value: str) -> boolparse bool
is_emptyfunc is_empty(value: str) -> boolempty test
joinfunc join(parts: Array[str], sep: str) -> strjoin array of strings

Examples

import std.string as string
func main():
let text = string.concat("Hello, ", "Thagore")
println(text)
import std.string as string
func main() -> i32:
if (string.contains("compiler", "pile") and string.starts_with("compiler", "com")):
return 0
return 1
import std.string as string
func main():
println(string.from_int(42))
println(string.from_f64(3.5))
println(string.from_bool(true))