StringSlice Struct
A lightweight struct that represents a slice of a string.
public struct StringSlice : ICharIteratorSee also
- Implements
Constructors
| Name | Description |
|---|---|
| StringSlice(string) | Initializes a new instance of the StringSlice struct. |
| StringSlice(string, NewLine) | Initializes a new instance of the StringSlice struct. |
| StringSlice(string, int, int) | Initializes a new instance of the StringSlice struct. |
| StringSlice(string, int, int, NewLine) | Initializes a new instance of the StringSlice struct. |
StringSlice overloads
StringSlice(string)
StringSlice.csInitializes a new instance of the StringSlice struct.
public StringSlice(string text)Parameters
textstring- The text.
StringSlice(string, NewLine)
StringSlice.csInitializes a new instance of the StringSlice struct.
StringSlice(string, int, int)
StringSlice.csInitializes a new instance of the StringSlice struct.
StringSlice(string, int, int, NewLine)
StringSlice.csInitializes a new instance of the StringSlice struct.
Parameters
Exceptions
Properties
| Name | Description |
|---|---|
| CurrentChar | Gets the current character. |
| CurrentRune | Gets the current Rune. Recognizes supplementary code points that cannot be covered by a single Char. |
| End | Gets or sets the end position (inclusive) within StringSlice.Text. |
| IsEmpty | Gets a value indicating whether this instance is empty. |
| Length | Gets the length. |
| Start | Gets or sets the start position within StringSlice.Text. |
CurrentChar
StringSlice.csCurrentRune
StringSlice.csGets or sets the end position (inclusive) within StringSlice.Text.
public int End { readonly get; set; }Property value
IsEmpty
StringSlice.csLength
StringSlice.csStart
StringSlice.csGets or sets the start position within StringSlice.Text.
public int Start { readonly get; set; }Property value
Indexers
| Name | Description |
|---|---|
| this[int] | Gets the Char at the specified index. |
this[int]
StringSlice.csMethods
| Name | Description |
|---|---|
| AsSpan() | Performs the as span operation. |
| IndexOf(char) | Searches for the specified character within this slice. |
| IndexOf(string, int, bool) | Searches the specified text within this slice. |
| IsEmptyOrWhitespace() | Determines whether this slice is empty or made only of whitespaces. |
| Match(string, int) | Matches the specified text. |
| Match(string, int, int) | Matches the specified text. |
| MatchLowercase(string, int) | Matches the specified text using lowercase comparison. |
| MatchLowercase(string, int, int) | Matches the specified text using lowercase comparison. |
| NextChar() | Goes to the next character, incrementing the StringSlice.Start position. |
| NextRune() | Goes to the next Rune, incrementing the StringSlice.Start position. If StringSlice.CurrentRune is a supplementary character, StringSlice.Start will be advanced by 2. |
| Overlaps(StringSlice) | Performs the overlaps operation. |
| PeekChar() | Peeks a character at the offset of 1 from the current StringSlice.Start position inside the range StringSlice.Start and StringSlice.End, returns `\0` if outside this range. |
| PeekChar(int) | Peeks a character at the specified offset from the current StringSlice.Start position inside the range StringSlice.Start and StringSlice.End, returns `\0` if outside this range. |
| PeekCharAbsolute(int) | Peeks a character at the specified offset from the current beginning of the string, without taking into account StringSlice.Start and StringSlice.End |
| PeekCharExtra(int) | Peeks a character at the specified offset from the current beginning of the slice without using the range StringSlice.Start or StringSlice.End, returns `\0` if outside the StringSlice.Text. |
| PeekRuneExtra(int) | Peeks a Rune at the specified offset from the current beginning of the slice without using the range StringSlice.Start or StringSlice.End, returns default if outside the StringSlice.Text. Recognizes supplementary code points that cannot be covered by a single Char. A positive offset value expects the high surrogate and a negative offset expects the low surrogate of the surrogate pair of a supplementary character at that position. |
| RuneAt(int) | Gets the Rune at the specified index. Recognizes supplementary code points that cannot be covered by a single Char. |
| SkipChar() | Goes to the next character, incrementing the StringSlice.Start position. |
| SkipSpacesToEndOfLineOrEndOfDocument() | Expect spaces until a end of line. Return false otherwise. |
| ToString() | Returns a String that represents this instance. |
| Trim() | Trims whitespaces from both the start and end of this slice. |
| TrimEnd() | Trims whitespaces at the end of this slice, starting from StringSlice.End position. |
| TrimStart() | Trims whitespaces at the beginning of this slice starting from StringSlice.Start position. |
| TrimStart(int) | Trims whitespaces at the beginning of this slice starting from StringSlice.Start position. |
AsSpan()
StringSlice.csIsEmptyOrWhitespace()
StringSlice.csMatchLowercase overloads
MatchLowercase(string, int)
StringSlice.csMatchLowercase(string, int, int)
StringSlice.csNextChar()
StringSlice.csGoes to the next character, incrementing the StringSlice.Start position.
public char NextChar()Returns
char The next character. `\0` is end of the iteration.
NextRune()
StringSlice.csGoes to the next Rune, incrementing the StringSlice.Start position. If StringSlice.CurrentRune is a supplementary character, StringSlice.Start will be advanced by 2.
public Rune NextRune()Returns
Rune The current rune or default if the next position contains an incomplete surrogate pair or StringSlice.IsEmpty.
Overlaps(StringSlice)
StringSlice.csPerforms the overlaps operation.
public bool Overlaps(StringSlice other)PeekChar overloads
PeekChar()
StringSlice.csPeeks a character at the offset of 1 from the current StringSlice.Start position inside the range StringSlice.Start and StringSlice.End, returns `\0` if outside this range.
public readonly char PeekChar()Returns
char The character at offset, returns `\0` if none.
PeekChar(int)
StringSlice.csPeeks a character at the specified offset from the current StringSlice.Start position inside the range StringSlice.Start and StringSlice.End, returns `\0` if outside this range.
PeekCharAbsolute(int)
StringSlice.csPeeks a character at the specified offset from the current beginning of the string, without taking into account StringSlice.Start and StringSlice.End
PeekCharExtra(int)
StringSlice.csPeeks a character at the specified offset from the current beginning of the slice without using the range StringSlice.Start or StringSlice.End, returns `\0` if outside the StringSlice.Text.
PeekRuneExtra(int)
StringSlice.csPeeks a Rune at the specified offset from the current beginning of the slice without using the range StringSlice.Start or StringSlice.End, returns default if outside the StringSlice.Text. Recognizes supplementary code points that cannot be covered by a single Char. A positive offset value expects the high surrogate and a negative offset expects the low surrogate of the surrogate pair of a supplementary character at that position.
RuneAt(int)
StringSlice.csGets the Rune at the specified index. Recognizes supplementary code points that cannot be covered by a single Char.
Parameters
indexint- The index into
StringSlice.Text.
Returns
Rune The rune at the specified index or default if the location contains an incomplete surrogate pair.
Exceptions
IndexOutOfRangeException- Thrown when the given
indexis out of range
SkipChar()
StringSlice.csGoes to the next character, incrementing the StringSlice.Start position.
public void SkipChar()SkipSpacesToEndOfLineOrEndOfDocument()
StringSlice.csToString()
StringSlice.csTrim()
StringSlice.csTrims whitespaces from both the start and end of this slice.
public void Trim()TrimEnd()
StringSlice.csTrims whitespaces at the end of this slice, starting from StringSlice.End position.
public bool TrimEnd()Returns
TrimStart overloads
TrimStart()
StringSlice.csTrims whitespaces at the beginning of this slice starting from StringSlice.Start position.
public bool TrimStart()Returns
bool true if it has reaches the end of the iterator
TrimStart(int)
StringSlice.csTrims whitespaces at the beginning of this slice starting from StringSlice.Start position.
Parameters
spaceCountint- The number of spaces trimmed.
Fields
| Name | Description |
|---|---|
| Empty | An empty string slice. |
| NewLine | Gets or sets the new line. |
| Text | The text of this slice. |
Empty
An empty string slice.
public static readonly StringSlice EmptyNewLine
Gets or sets the new line.
public NewLine NewLineText
The text of this slice.
public readonly string Text