std.string
concat function
pub fn concat(a: string, b: string): string
The two joined — what + on strings compiles to.
stdlib/std/string.lyr:19
fromInt function
pub fn fromInt(value: int): string
The decimal text of the value.
stdlib/std/string.lyr:22
fromUint function
pub fn fromUint(value: uint): string
The decimal text of an unsigned value.
stdlib/std/string.lyr:27
fromFloat function
pub fn fromFloat(value: float): string
The decimal text of the value.
stdlib/std/string.lyr:29
fromBool function
pub fn fromBool(value: bool): string
"true" or "false".
stdlib/std/string.lyr:31
fromChar function
pub fn fromChar(value: char): string
The character as a one-character string.
stdlib/std/string.lyr:33
repeat function
pub fn repeat(value: string, count: int): string
The string repeated count times — what s * n compiles to.
stdlib/std/string.lyr:38
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:49
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:51
substring function
pub fn substring(value: string, start: int, count: int): string
count characters from start, both in code points.
stdlib/std/string.lyr:53
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:59
contains function
pub fn contains(value: string, needle: string): bool
Whether needle occurs.
stdlib/std/string.lyr:61
startsWith function
pub fn startsWith(value: string, prefix: string): bool
Whether the string begins with prefix.
stdlib/std/string.lyr:63
endsWith function
pub fn endsWith(value: string, suffix: string): bool
Whether the string ends with suffix.
stdlib/std/string.lyr:65
trim function
pub fn trim(value: string): string
Without leading and trailing whitespace.
stdlib/std/string.lyr:68
toUpper function
pub fn toUpper(value: string): string
Upper-cased, ordinal — the same result everywhere, no culture involved.
stdlib/std/string.lyr:72
toLower function
pub fn toLower(value: string): string
Lower-cased, ordinal.
stdlib/std/string.lyr:74
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:79
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:83
isDigit function
pub fn isDigit(c: char): bool
'0' through '9'.
stdlib/std/string.lyr:103
isAlpha function
pub fn isAlpha(c: char): bool
An ASCII letter.
stdlib/std/string.lyr:109
isAlphanumeric function
pub fn isAlphanumeric(c: char): bool
An ASCII letter or a digit.
stdlib/std/string.lyr:114
isWhitespace function
pub fn isWhitespace(c: char): bool
Space, tab, \n or \r.
stdlib/std/string.lyr:119
isUpper function
pub fn isUpper(c: char): bool
'A' through 'Z'.
stdlib/std/string.lyr:124
isLower function
pub fn isLower(c: char): bool
'a' through 'z'.
stdlib/std/string.lyr:129
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:136
digitToChar function
pub fn digitToChar(value: int): ?char
The digit as a character, or null outside 0..9.
stdlib/std/string.lyr:144
isEmpty function
pub fn isEmpty(value: string): bool
Whether the length is zero.
stdlib/std/string.lyr:154
isBlank function
pub fn isBlank(value: string): bool
Empty or whitespace only.
stdlib/std/string.lyr:159
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:174
lastIndexOf function
pub fn lastIndexOf(value: string, needle: string): int
The LAST occurrence.
stdlib/std/string.lyr:192
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:213
join function
pub fn join(parts: string[], separator: string): string
Joins the parts with a separator: the inverse of split.
stdlib/std/string.lyr:230
splitLines function
pub fn splitLines(value: string): string[]
Splits at line breaks. Both \r\n and \n count.
stdlib/std/string.lyr:245
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:251
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:262
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:285
trimStart function
pub fn trimStart(value: string): string
Without leading whitespace.
stdlib/std/string.lyr:298
trimEnd function
pub fn trimEnd(value: string): string
Without trailing whitespace.
stdlib/std/string.lyr:308
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:318
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:328
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:345
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:378
parseBool function
pub fn parseBool(value: string): ?bool
Exactly "true" or "false"; anything else is null.
stdlib/std/string.lyr:422
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:435
fromChars function
pub fn fromChars(chars: char[]): string
The characters joined back into one string — the inverse of toChars.
stdlib/std/string.lyr:492
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:509
newStringBuilder function
pub fn newStringBuilder(): StringBuilder
An empty builder.
stdlib/std/string.lyr:564