Skip to content
CShift0.32

StringSlice

Struct · built-in type

struct StringSlice

A view of a part of a string: s[i..j], and the results of String.Trim, String.Split and String.Substring. Nothing is copied; StringSlice.ToString copies.

A string converts to a StringSlice for free, so the functions of String take slices and work on parts of a text. == compares the text and + joins it like a string. Slices are IEquatable, IHashable and IComparable like strings: keys of a Dictionary, elements of a sorted List.

Name Description
Length The length in bytes.
int Length

The length in bytes.

Name Description
ToString A new string with the text of the slice.
Ptr A pointer to the first byte (unsafe); the text is not followed by a 0 byte.
CStr The text as a C string (unsafe): followed by a 0 byte, for C functions.
AsBytes The bytes of the text (UTF-8) as a view, for functions that take bytes; nothing is copied.
string ToString()

A new string with the text of the slice.

char* Ptr()

A pointer to the first byte (unsafe); the text is not followed by a 0 byte.

char* CStr()

The text as a C string (unsafe): followed by a 0 byte, for C functions. A slice that reaches the end of its string is passed as it is; any other slice is copied into a string that lives until the end of the statement.

ReadOnlySlice<uint8> AsBytes()

The bytes of the text (UTF-8) as a view, for functions that take bytes; nothing is copied. (A StringSlice converts to ReadOnlySlice<char> by itself.)