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:52
substring function
pub fn substring(value: string, start: int, count: int): string
count characters from start, both in code points.
stdlib/std/string.lyr:55
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:62
contains function
pub fn contains(value: string, needle: string): bool
Whether needle occurs.
stdlib/std/string.lyr:65
startsWith function
pub fn startsWith(value: string, prefix: string): bool
Whether the string begins with prefix.
stdlib/std/string.lyr:68
endsWith function
pub fn endsWith(value: string, suffix: string): bool
Whether the string ends with suffix.
stdlib/std/string.lyr:71
trim function
pub fn trim(value: string): string
Without leading and trailing whitespace.
stdlib/std/string.lyr:75
toUpper function
pub fn toUpper(value: string): string
Upper-cased, ordinal — the same result everywhere, no culture involved.
stdlib/std/string.lyr:80
toLower function
pub fn toLower(value: string): string
Lower-cased, ordinal.
stdlib/std/string.lyr:83
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:89
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:94
fromChars function
pub fn fromChars(chars: char[]): string
The characters joined back into one string — the inverse of toChars. Native since v1.14:
one call instead of one string per character.
stdlib/std/string.lyr:99
utf8Encode function
pub fn utf8Encode(value: string): uint8[]
The string as UTF-8 bytes — the inverse of utf8Decode, and what a file or a socket
actually carries.
stdlib/std/string.lyr:108
utf8Decode function
pub fn utf8Decode(bytes: uint8[]): ?string
The bytes as a string, STRICTLY: invalid UTF-8 answers null rather than a U+FFFD quietly
standing in for the data — the difference to readText, whose replacement decoding is
documented there.
stdlib/std/string.lyr:114
isDigit function
pub fn isDigit(c: char): bool
'0' through '9'.
stdlib/std/string.lyr:423
isAlpha function
pub fn isAlpha(c: char): bool
An ASCII letter.
stdlib/std/string.lyr:429
isAlphanumeric function
pub fn isAlphanumeric(c: char): bool
An ASCII letter or a digit.
stdlib/std/string.lyr:434
isWhitespace function
pub fn isWhitespace(c: char): bool
Space, tab, \n or \r.
stdlib/std/string.lyr:439
isUpper function
pub fn isUpper(c: char): bool
'A' through 'Z'.
stdlib/std/string.lyr:444
isLower function
pub fn isLower(c: char): bool
'a' through 'z'.
stdlib/std/string.lyr:449
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:456
digitToChar function
pub fn digitToChar(value: int): ?char
The digit as a character, or null outside 0..9.
stdlib/std/string.lyr:464
isEmpty function
pub fn isEmpty(value: string): bool
Whether the length is zero.
stdlib/std/string.lyr:474
isBlank function
pub fn isBlank(value: string): bool
Empty or whitespace only.
stdlib/std/string.lyr:482
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:504
lastIndexOf function
pub fn lastIndexOf(value: string, needle: string): int
The LAST occurrence.
stdlib/std/string.lyr:510
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:519
join function
pub fn join(parts: string[], separator: string): string
Joins the parts with a separator: the inverse of split. One native call — a left fold
would copy the whole result once per part.
stdlib/std/string.lyr:528
splitLines function
pub fn splitLines(value: string): string[]
Splits at line breaks. Both \r\n and \n count.
stdlib/std/string.lyr:533
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:539
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:547
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:553
trimStart function
pub fn trimStart(value: string): string
Without leading whitespace.
stdlib/std/string.lyr:561
trimEnd function
pub fn trimEnd(value: string): string
Without trailing whitespace.
stdlib/std/string.lyr:567
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:574
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:581
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:595
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:629
parseBool function
pub fn parseBool(value: string): ?bool
Exactly "true" or "false"; anything else is null.
stdlib/std/string.lyr:674
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:687
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, an implementation detail, NOT the
character count. Measure the built string instead. (It would carry @Deprecated, but an
attribute cannot sit on a member yet; the removal is planned for 2.0 regardless.)
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. One native call over the filled slice; a left fold would copy the whole result once per piece, the exact cost the builder exists to avoid. Reads and never consumes: building twice yields the same string.
stdlib/std/string.lyr:751
newStringBuilder function
pub fn newStringBuilder(): StringBuilder
An empty builder.
stdlib/std/string.lyr:811