std.string
concat function
pub fn concat(a: string, b: string): string
The two joined — what + on strings compiles to.
stdlib/std/string.lyr:15
fromInt function
pub fn fromInt(value: int): string
The decimal text of the value.
stdlib/std/string.lyr:18
fromUint function
pub fn fromUint(value: uint): string
The decimal text of an unsigned value.
stdlib/std/string.lyr:23
fromFloat function
pub fn fromFloat(value: float): string
The decimal text of the value.
stdlib/std/string.lyr:25
fromBool function
pub fn fromBool(value: bool): string
"true" or "false".
stdlib/std/string.lyr:27
fromChar function
pub fn fromChar(value: char): string
The character as a one-character string.
stdlib/std/string.lyr:29
repeat function
pub fn repeat(value: string, count: int): string
The string repeated count times — what s * n compiles to.
stdlib/std/string.lyr:34
length function
pub fn length(value: string): int
The length in code points — the unit every position in this module uses.
stdlib/std/string.lyr:45
charAt function
pub fn charAt(value: string, index: int): char
The character at a code-point position. O(n): a position counts code points, not bytes.
stdlib/std/string.lyr:47
substring function
pub fn substring(value: string, start: int, count: int): string
count characters from start, both in code points.
stdlib/std/string.lyr:49
indexOf function
pub fn indexOf(value: string, needle: string): int
The first position of needle in code points, or -1 — ready for charAt and
substring.
stdlib/std/string.lyr:55
contains function
pub fn contains(value: string, needle: string): bool
Whether needle occurs.
stdlib/std/string.lyr:57
startsWith function
pub fn startsWith(value: string, prefix: string): bool
Whether the string begins with prefix.
stdlib/std/string.lyr:59
endsWith function
pub fn endsWith(value: string, suffix: string): bool
Whether the string ends with suffix.
stdlib/std/string.lyr:61
trim function
pub fn trim(value: string): string
Without leading and trailing whitespace.
stdlib/std/string.lyr:64
toUpper function
pub fn toUpper(value: string): string
Upper-cased, ordinal — the same result everywhere, no culture involved.
stdlib/std/string.lyr:68
toLower function
pub fn toLower(value: string): string
Lower-cased, ordinal.
stdlib/std/string.lyr:70
split function
pub fn split(value: string, separator: string): string[]
The parts between occurrences of separator. An empty separator panics: "split into
what" has no answer.
stdlib/std/string.lyr:75
toChars function
pub fn toChars(value: string): char[]
The characters as an array, in one O(n) pass — what for (c in s) uses.
stdlib/std/string.lyr:79
isDigit function
pub fn isDigit(c: char): bool
'0' through '9'.
stdlib/std/string.lyr:99
isAlpha function
pub fn isAlpha(c: char): bool
An ASCII letter.
stdlib/std/string.lyr:105
isAlphanumeric function
pub fn isAlphanumeric(c: char): bool
An ASCII letter or a digit.
stdlib/std/string.lyr:110
isWhitespace function
pub fn isWhitespace(c: char): bool
Space, tab, \n or \r.
stdlib/std/string.lyr:115
isUpper function
pub fn isUpper(c: char): bool
'A' through 'Z'.
stdlib/std/string.lyr:120
isLower function
pub fn isLower(c: char): bool
'a' through 'z'.
stdlib/std/string.lyr:125
charToDigit function
pub fn charToDigit(c: char): ?int
The numeric value of a digit, or null when it is not one.
?int rather than -1: a failure the caller has to handle belongs in the type.
stdlib/std/string.lyr:132
digitToChar function
pub fn digitToChar(value: int): ?char
The digit as a character, or null outside 0..9.
stdlib/std/string.lyr:140
isEmpty function
pub fn isEmpty(value: string): bool
Whether the length is zero.
stdlib/std/string.lyr:150
isBlank function
pub fn isBlank(value: string): bool
Empty or whitespace only.
stdlib/std/string.lyr:155
indexOfFrom function
pub fn indexOfFrom(value: string, needle: string, start: int): int
Searches from a position. -1 when nothing is found, as in indexOf.
stdlib/std/string.lyr:170
lastIndexOf function
pub fn lastIndexOf(value: string, needle: string): int
The LAST occurrence.
stdlib/std/string.lyr:188
count function
pub fn count(value: string, needle: string): int
How often needle occurs, WITHOUT overlap.
Overlapping occurrences are not counted: count("aaa", "aa") is 1, not 2. This matches
replace.
stdlib/std/string.lyr:209
join function
pub fn join(parts: string[], separator: string): string
Joins the parts with a separator: the inverse of split.
stdlib/std/string.lyr:226
splitLines function
pub fn splitLines(value: string): string[]
Splits at line breaks. Both \r\n and \n count.
stdlib/std/string.lyr:241
splitFirst function
pub fn splitFirst(value: string, separator: string): string[]
Splits at the FIRST occurrence; the rest stays whole, for key=value=more.
stdlib/std/string.lyr:247
replace function
pub fn replace(value: string, needle: string, replacement: string): string
Every non-overlapping occurrence of needle replaced. An empty needle changes nothing.
stdlib/std/string.lyr:258
replaceFirst function
pub fn replaceFirst(value: string, needle: string, replacement: string): string
The first occurrence replaced; without one the string comes back unchanged.
stdlib/std/string.lyr:281
trimStart function
pub fn trimStart(value: string): string
Without leading whitespace.
stdlib/std/string.lyr:294
trimEnd function
pub fn trimEnd(value: string): string
Without trailing whitespace.
stdlib/std/string.lyr:304
padStart function
pub fn padStart(value: string, width: int, fill: char): string
Pads at the front until width is reached. A longer string is left unchanged; truncating
would lose data in a function that only formats.
stdlib/std/string.lyr:314
padEnd function
pub fn padEnd(value: string, width: int, fill: char): string
Pads at the end until width is reached. A longer string is left unchanged; truncating
would lose data in a function that only formats.
stdlib/std/string.lyr:324
parseInt function
pub fn parseInt(value: string): ?int
"-42" becomes -42, anything else null.
No overflow protection: a number beyond int64 wraps rather than yielding null. Detecting
it would need a division per digit.
stdlib/std/string.lyr:341
parseIntRadix function
pub fn parseIntRadix(value: string, radix: int): ?int
From a base of 2 to 36. Letters continue from a/A.
stdlib/std/string.lyr:374
parseBool function
pub fn parseBool(value: string): ?bool
Exactly "true" or "false"; anything else is null.
stdlib/std/string.lyr:418
parseFloat function
pub fn parseFloat(value: string): ?float
"3.5", "-0.25" and "42" become floating point; everything else is null.
Without exponent notation (1e9), which would need a state machine of its own.
stdlib/std/string.lyr:431
fromChars function
pub fn fromChars(chars: char[]): string
The characters joined back into one string — the inverse of toChars.
stdlib/std/string.lyr:488
StringBuilder class
pub class StringBuilder
Builds a string piece by piece.
s = s + part in a loop is quadratic: every step copies the whole string so far. The builder
collects the parts and joins them once.
The backing is a doubling string[], written by hand because this module must not import
std.collections.
parts: string[]
The collected pieces; count says how many are filled.
count: int
How many entries of parts are real.
pub static fn new(): StringBuilder
An empty builder.
pub fn length(): int
How many pieces were appended — the PIECE count, not the character count.
pub mut fn append(value: string): void
Adds a piece; the backing array doubles when full.
pub mut fn appendLine(value: string): void
Adds the piece and a \n.
pub mut fn appendChar(value: char): void
Adds one character.
pub fn build(): string
The pieces joined once — the point of collecting them.
stdlib/std/string.lyr:505
newStringBuilder function
pub fn newStringBuilder(): StringBuilder
An empty builder. Prefer StringBuilder.new(); deprecating this one waits on attribute
visibility — @Deprecated lives in std.core, and importing that here would be a cycle.
stdlib/std/string.lyr:561