Substring Class

Summary

Encapsulates a string to treat it as a variable substring without the memory allocation and garbage collection costs of System.String.Substring(System.Int32,System.Int32).
Assembly
Weaver.dll
Namespace
Weaver
Interfaces
Base Types
  • Object
graph BT Type-->Base0["Object"] Type-.->Interface0["IComparable<Substring>"] Type["Substring"] class Type type-node

Syntax

public sealed class Substring : IComparable<Substring>

Constructors

Name Summary
Substring() Creates a new Weaver.Substring without assigning the encapsulated string or indices.
Substring(string) Creates a new Weaver.Substring with the Weaver.Substring.startIndex at 0 and the Weaver.Substring.endIndex equal to rawString.Length.
Substring(string, int) Creates a new Weaver.Substring with the specified Weaver.Substring.startIndex and the Weaver.Substring.endIndex equal to rawString.Length.
Substring(string, int, int) Creates a new Weaver.Substring with the specified parameters.
Substring(Substring) Creates a new Weaver.Substring as a copy of the specified `original`.

Fields

Name Constant Value Summary
endIndex
The character index in the Weaver.Substring.rawString of the character immediately after the end of this substring.
rawString
The original encapsulated string.
startIndex
The character index in the Weaver.Substring.rawString of the start of this substring.

Properties

Name Value Summary
IsAtEnd bool
Returns true if the end index is at or past the end of the Weaver.Substring.rawString.
IsValid bool
Returns true if the Weaver.Substring.startIndex and Weaver.Substring.endIndex denote a valid substring within the Weaver.Substring.rawString.
Length int
The number of characters in the current substring.
this[int] char
Returns Weaver.Substring.rawString[Weaver.Substring.startIndex + i]

Methods

Name Value Summary
AppendTo(StringBuilder) void
Appends the characters of this Weaver.Substring to the specified `text`.

If this Weaver.Substring is currently invalid, it appends '\0' (the NUL char).
CompareTo(Substring) int
Compares the characters in `this` to `other`.
CopyFrom(Substring) void
Copies the Weaver.Substring.rawString, Weaver.Substring.startIndex, and Weaver.Substring.endIndex from `other`.
Equals(Object) bool
Returns true if `this` contains the same characters as `obj` (as a string or Weaver.Substring).
Equals(string, int, int, string, int, int) bool
Returns true if the specified substring within `a` contains the same characters as the specified substring within `b`.
static
Equals(string, string, int, int) bool
Returns true if the specified substring within `a` contains the same characters as the specified substring within `b`.
static
GetFileNameWithoutExtension(string) Substring
Returns a new Weaver.Substring encapsulating the file name within the specified `path`, without its file extension.
static
GetHashCode() int
Returns the hash code of the current value of this Weaver.Substring.
IndexOf(char, int) int
Returns the first index of the specified `value` within this substring, or -1 if it isn't found.

The returned value is relative to the start of the Weaver.Substring.rawString.
IndexOfAny(char[], int) int
Returns the first index of any of the characters in `anyOf` within this substring, or -1 if none are found.

The returned value is relative to the start of the Weaver.Substring.rawString.
LastIndexOf(char) int
Returns the last index of the specified `value` within this substring, or -1 if it isn't found.

The returned value is relative to the start of the Weaver.Substring.rawString.
LastIndexOfAny(char[]) int
Returns the last index of any of the characters in `anyOf` within this substring, or -1 if none are found.

The returned value is relative to the start of the Weaver.Substring.rawString.
MoveToNextDirectory() bool
Adjusts the Weaver.Substring.startIndex and Weaver.Substring.endIndex to encapsulate the name of the next directory within the Weaver.Substring.rawString.
RemoveFileExtension() void
Adjusts the Weaver.Substring.endIndex to remove the file extension from the end of this Weaver.Substring (if it has one).
Set(string) void
Assigns the specified Weaver.Substring.rawString, sets the Weaver.Substring.startIndex to 0, and the Weaver.Substring.endIndex equal to rawString.Length.
Set(string, int) void
Assigns the specified Weaver.Substring.rawString, sets the specified Weaver.Substring.startIndex, and the Weaver.Substring.endIndex equal to rawString.Length.
Set(string, int, int) void
Assigns the specified parameters to this Weaver.Substring.
StartsWith(string) bool
Returns true if this Weaver.Substring starts with the characters in `fullString`.
StartsWith(string, int, int) bool
The parameters denote a substring within the `fullString`. This method returns true if this Weaver.Substring starts with the same characters contained in that substring.
StartsWith(Substring) bool
Returns true if this Weaver.Substring starts with the characters in `other`.
ToDetailedString() string
Returns a description of the current state of this Weaver.Substring.
ToString() string
Returns a new string containing the current value of this Weaver.Substring.

Operators

Name Value Summary
implicit operator string(Substring) string
operator !=(Substring, string) bool
operator !=(Substring, Substring) bool
operator ==(Substring, string) bool
operator ==(Substring, Substring) bool