string
sealed class stringAvailable without an import.
Immutable UTF-8 text, spelled string in Wax and available without an import.
length, search results, and slice arguments count bytes. Chars iterates
Unicode code points; Graphemes groups code points into displayed-character
boundaries. Search and equality compare exact bytes without Unicode normalization.
Transforms produce strings without changing the receiver. Slice,
ToStringSlice, and ToReadOnlySpan borrow storage; Substring copies it.
This example returns 5: the four code points in café occupy five UTF-8 bytes.
api fn Main() : int32 {
string text = "café";
int32 accentOffset = text.IndexOf("é");
string accent = text.Substring(accentOffset, 2);
return accent == "é" ? text.length : -1;
}
Inherits from object. Follow these links for inherited members.
Members
lengthfield
public native readonly int32 lengthThe number of UTF-8 bytes, excluding any terminator. This is not a character or grapheme count.
Emptyconst
const string Empty = ""The empty string, with zero bytes and zero graphemes.
GetHashCodemethod
public override fn GetHashCode() : uint32Hashes the UTF-8 content. Equal strings have equal hashes; a hash is not a unique identifier or a persisted checksum.
Equalsmethod
public override fn Equals(object other) : boolReturns true when other is a string with identical UTF-8 bytes. Other object types compare
unequal.
Containsmethod
public fn Contains<T>(T needle) : bool where T is StringLikeTests for an exact, case-sensitive byte sequence. An empty needle is always present. Accepts
strings and other StringLike values.
StartsWithmethod
public fn StartsWith<T>(T prefix) : bool where T is StringLikeTests for an exact, case-sensitive prefix. An empty prefix matches; a prefix longer than this string does not.
EndsWithmethod
public fn EndsWith<T>(T suffix) : bool where T is StringLikeTests for an exact, case-sensitive suffix. An empty suffix matches; a suffix longer than this string does not.
IndexOfmethod
public fn IndexOf<T>(T needle) : int32 where T is StringLikeReturns the byte offset of the first exact match, or -1 when absent. An empty needle
returns 0. Matching is case-sensitive and does not normalize Unicode.
LastIndexOfmethod
public fn LastIndexOf<T>(T needle) : int32 where T is StringLikeReturns the byte offset of the last exact match, or -1 when absent. An empty needle
returns length. Matching is case-sensitive and does not normalize Unicode.
ByteAtmethod
public fn ByteAt(int32 index) : uint8Returns the byte at a zero-based UTF-8 byte index. Returns 0 for a negative index or an
index at or beyond length.
CharAtByteOffsetmethod
public fn CharAtByteOffset(int32 offset) : charDecodes the Unicode code point starting at a UTF-8 byte offset. Returns U+0000 outside the string and U+FFFD when the offset starts inside a multibyte sequence.
LastCharmethod
public fn LastChar() : charReturns the final Unicode code point, or U+0000 for an empty string. A code point can be only part of a displayed character.
FirstBytemethod
public fn FirstByte() : uint8Returns the first UTF-8 byte, or 0 for an empty string.
LastBytemethod
public fn LastByte() : uint8Returns the final UTF-8 byte, or 0 for an empty string. For a multibyte code point this is
a continuation byte.
FirstCharmethod
public fn FirstChar() : charReturns the first Unicode code point, or U+0000 for an empty string.
IsEmptymethod
public fn IsEmpty() : boolReturns true when length is zero.
Substringmethod
public fn Substring(int32 start, int32 len) : stringCopies a byte range into an independent string. Negative start becomes zero; start >= length returns an empty string. Negative len, or a length past the end, selects the
remaining bytes. After clamping, both endpoints must be UTF-8 code-point boundaries or the
operation panics. Use Slice for a borrowed view.
Trimmethod
public fn Trim() : stringRemoves leading and trailing Unicode whitespace. Returns this string when unchanged and an empty string when all characters are whitespace.
TrimStartmethod
public fn TrimStart() : stringRemoves leading Unicode whitespace. Returns this string when unchanged.
TrimEndmethod
public fn TrimEnd() : stringRemoves trailing Unicode whitespace. Returns this string when unchanged.
Replacemethod
public fn Replace(string old, string replacement) : stringReplaces all non-overlapping, case-sensitive matches from left to right. An empty old, no
matches, or a result exceeding the maximum byte length returns this string unchanged.
Replacement text is not searched again.
ReplaceFirstmethod
public fn ReplaceFirst(string old, string replacement) : stringReplaces only the first case-sensitive match. An empty old, no match, or a result
exceeding the maximum byte length returns this string unchanged.
Splitmethod
public fn Split(string delimiter) : string[]Splits on exact, non-overlapping delimiter matches and returns a new array of strings. Preserves empty leading, trailing, and adjacent segments. An empty delimiter returns a one- element array containing this string; an empty input also produces one empty segment.
PadLeftmethod
public fn PadLeft(int32 charCount, char padChar) : stringPrepends charCount copies of padChar; the count is padding to add, not a target width. A
nonpositive count or oversized result returns this string. An invalid Unicode scalar is
encoded as U+FFFD.
PadRightmethod
public fn PadRight(int32 charCount, char padChar) : stringAppends charCount copies of padChar; the count is padding to add, not a target width. A
nonpositive count or oversized result returns this string. An invalid Unicode scalar is
encoded as U+FFFD.
InsertAtmethod
public fn InsertAt(int32 index, string value) : stringInserts value at a UTF-8 byte offset, clamping index to [0, length]. The clamped
position must be a code-point boundary or the operation panics. An empty value returns this
string without checking the index; an oversized result also returns this string.
RemoveRangemethod
public fn RemoveRange(int32 start, int32 count) : stringRemoves up to count UTF-8 bytes. A nonpositive count or a start at or beyond the end
returns this string. Negative start becomes zero and an excessive count is clamped to the
remaining bytes. The resulting range must start and end on code-point boundaries or the
operation panics.
Countmethod
public fn Count<T>(T needle) : int32 where T is StringLikeCounts exact, case-sensitive, non-overlapping matches from left to right. An empty needle
returns 0.
CompareTomethod
public fn CompareTo(string other) : int32Compares UTF-8 bytes lexicographically, returning -1, 0, or 1. A matching prefix sorts
before a longer string. This is ordinal, case-sensitive ordering, without locale collation
or Unicode normalization.
ToStringSlicemethod
public fn ToStringSlice() : StringSliceBorrows a view of all UTF-8 bytes without copying. The scoped view cannot outlive its backing storage.
ToStringmethod
public override fn ToString() : stringReturns this string unchanged.
ToReadOnlySpanmethod
public fn ToReadOnlySpan() : ReadOnlySpan<uint8>Borrows the UTF-8 bytes without a terminator or a copy. The scoped view permits byte reads but cannot mutate the string.
FromUtf8method
public static fn FromUtf8(ReadOnlySpan<uint8> bytes) : string throws Utf8ErrorValidates and copies UTF-8 bytes into an independent string. Throws Utf8Error at the first
invalid byte offset, including truncated sequences, overlong encodings, surrogate code
points, and values above U+10FFFF. Empty input produces an empty string.
FromUtf8Lossymethod
public static fn FromUtf8Lossy(ReadOnlySpan<uint8> bytes) : stringCopies UTF-8 bytes, replacing each undecodable byte with U+FFFD and advancing one byte before trying again. Valid sequences are preserved. Empty input produces an empty string; a result exceeding the maximum byte length panics.
Slicemethod
public fn Slice(int32 start, int32 len) : StringSliceBorrows the byte range [start, start + len) without copying. Negative arguments, an out-
of-range endpoint, or an endpoint inside a UTF-8 code point cause a panic. An empty slice at
length is valid. Use Substring for an independent string with clamped arguments.
Bytesmethod
public fn Bytes() : ByteIteratorIterates UTF-8 bytes from first to last. An empty string yields no elements.
Charsmethod
public fn Chars() : CharIteratorIterates Unicode code points from first to last. Code points are not necessarily whole
displayed characters; use Graphemes for those boundaries.
CharsReversemethod
public fn CharsReverse() : ReverseCharIteratorIterates Unicode code points from last to first, preserving each code point. This does not reverse grapheme clusters as units.
Graphemesmethod
public fn Graphemes() : GraphemeIteratorIterates extended grapheme clusters as borrowed StringSlice views. A cluster may contain
several code points, such as a letter plus combining marks. Empty input yields no clusters.
GraphemeCountmethod
public fn GraphemeCount() : int32Counts extended grapheme clusters by scanning the string. Returns zero for an empty string;
this differs from the UTF-8 byte count in length.
ToUppermethod
public fn ToUpper() : stringApplies full Unicode uppercase mapping without locale-specific rules. Mapping can expand a
code point into several code points and change the byte length. Use ToUpperLocale for
locale-specific casing.
ToLowermethod
public fn ToLower() : stringApplies full Unicode lowercase mapping, including contextual Greek final sigma, without
locale-specific rules. Mapping can change the byte length. Use ToLowerLocale for locale-
specific casing.
ToUpperLocalemethod
public fn ToUpperLocale(Locale loc) : stringApplies full Unicode uppercase mapping with the selected locale rules. Locale.Invariant
matches ToUpper; Lithuanian, Turkish, and Azeri apply their additional casing rules.
Mapping can change the number of code points.
ToLowerLocalemethod
public fn ToLowerLocale(Locale loc) : stringApplies full Unicode lowercase mapping with the selected locale rules. Locale.Invariant
matches ToLower; Lithuanian, Turkish, and Azeri apply their additional casing rules.
Mapping can change the number of code points.