docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct SubString

    Represents a portion of a string value.

    Implements
    IEquatable<string>
    IComparable<string>
    IEquatable<SubString>
    IComparable<SubString>
    IEnumerable<char>
    IEnumerable
    Inherited Members
    ValueType.Equals(object)
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.InferenceEngine.Tokenization
    Assembly: Unity.InferenceEngine.Tokenization.dll
    Syntax
    public readonly struct SubString : IEquatable<string>, IComparable<string>, IEquatable<SubString>, IComparable<SubString>, IEnumerable<char>, IEnumerable
    Remarks

    This type is required as ReadOnlySpan<T> has some blocking constraints.

    Constructors

    SubString(string)

    Initializes a new instance of the SubString type.

    Declaration
    public SubString(string source)
    Parameters
    Type Name Description
    string source

    The source string from which this SubString is built. This constructor keeps the whole source.

    SubString(string, Range)

    Initializes a new instance of the SubString type.

    Declaration
    public SubString(string source, Range offsets)
    Parameters
    Type Name Description
    string source

    The source string from which this SubString is built.

    Range offsets

    The bounds of the portion of Source to keep.

    Fields

    k_Comparer

    Efficiently compares SubString instances.

    Declaration
    public static readonly IEqualityComparer<SubString> k_Comparer
    Field Value
    Type Description
    IEqualityComparer<SubString>

    Properties

    IsApplied

    Tells whether the portion covers the source string.

    Declaration
    public bool IsApplied { get; }
    Property Value
    Type Description
    bool

    IsEmpty

    Tells whether this instance is empty.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    bool

    IsNull

    Tells whether the substring does not reference any valid source.

    Declaration
    public bool IsNull { get; }
    Property Value
    Type Description
    bool

    IsNullOrWhiteSpace

    Tells whether this instance is null, empty or if it just contains white spaces.

    Declaration
    public bool IsNullOrWhiteSpace { get; }
    Property Value
    Type Description
    bool

    this[int]

    Gets the character ar index.

    Declaration
    public char this[int index] { get; }
    Parameters
    Type Name Description
    int index

    Index of the character to get.

    Property Value
    Type Description
    char

    this[Range]

    Gets a portion of this instance.

    Declaration
    public SubString this[Range offsets] { get; }
    Parameters
    Type Name Description
    Range offsets

    The bounds of the subpart to extract.

    Property Value
    Type Description
    SubString

    A new SubString instance.

    Length

    The number of char of this portion.

    Declaration
    public int Length { get; }
    Property Value
    Type Description
    int

    Offset

    The lower bound of the portion of Source to keep.

    Declaration
    public int Offset { get; }
    Property Value
    Type Description
    int

    Offsets

    Gets the bounds of the subpart of the original string0

    Declaration
    public Range Offsets { get; }
    Property Value
    Type Description
    Range

    Source

    The source string from which this SubString is built.

    Declaration
    public string Source { get; }
    Property Value
    Type Description
    string

    UtfLength

    The number of Utf-8 valid characters of this portion.

    Declaration
    public int UtfLength { get; }
    Property Value
    Type Description
    int

    Methods

    Apply()

    Returns a new SubString value which source string is the portion of this one.

    Declaration
    public SubString Apply()
    Returns
    Type Description
    SubString

    A new SubString value which source is the portion of this one.

    Remarks

    If the hash code has already been computed for this SubString, it is copied to the new one.

    AsSpan()

    Creates a new read-only span over a string.

    Declaration
    public ReadOnlySpan<char> AsSpan()
    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    AsSpan(int, int)

    Creates a new read-only span over a portion of the target string from a specified position for a specified number of characters.

    Declaration
    public ReadOnlySpan<char> AsSpan(int offset, int length)
    Parameters
    Type Name Description
    int offset

    The index at which to begin this slice.

    int length

    The desired length for the slice.

    Returns
    Type Description
    ReadOnlySpan<char>

    The read-only span representation of the string.

    CompareTo(string)

    Declaration
    public int CompareTo(string other)
    Parameters
    Type Name Description
    string other
    Returns
    Type Description
    int

    CompareTo(SubString)

    Declaration
    public int CompareTo(SubString other)
    Parameters
    Type Name Description
    SubString other
    Returns
    Type Description
    int

    Deconstruct(out string, out Range)

    Deconstructs this SubString.

    Declaration
    public void Deconstruct(out string source, out Range offsets)
    Parameters
    Type Name Description
    string source

    The source string from which this SubString is built.

    Range offsets

    The bounds of the portion of Source to keep.

    Equals(string)

    Declaration
    public bool Equals(string other)
    Parameters
    Type Name Description
    string other
    Returns
    Type Description
    bool

    Equals(SubString)

    Declaration
    public bool Equals(SubString other)
    Parameters
    Type Name Description
    SubString other
    Returns
    Type Description
    bool

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    ValueType.GetHashCode()

    GetHashCode(SubString?, SubString?)

    Computes a hashcode of this SubString instance with its prefix and suffix like if they were combined.

    Declaration
    public int GetHashCode(SubString? prefix, SubString? suffix)
    Parameters
    Type Name Description
    SubString? prefix

    A prefix value to combine with this.

    SubString? suffix

    A suffix value to combine with this.

    Returns
    Type Description
    int

    The hashcode of ""

    GetHashCode(ReadOnlySpan<char>, SubString?, SubString?)

    Computes a hashcode of this SubString instance with its prefix and suffix like if they were combined.

    Declaration
    public static int GetHashCode(ReadOnlySpan<char> value, SubString? prefix = null, SubString? suffix = null)
    Parameters
    Type Name Description
    ReadOnlySpan<char> value

    A value to hash.

    SubString? prefix

    A prefix value to combine with this.

    SubString? suffix

    A suffix value to combine with this.

    Returns
    Type Description
    int

    The hashcode of ""

    IndexOf(SubString, int, StringComparison)

    Returns the index of the first match of sub, starting from startIndex, or -1.

    Declaration
    public int IndexOf(SubString sub, int startIndex = 0, StringComparison comparison = StringComparison.Ordinal)
    Parameters
    Type Name Description
    SubString sub

    The pattern to find.

    int startIndex

    The index from which to start looking for sub.

    StringComparison comparison

    string comnparison method.

    Returns
    Type Description
    int

    The index of the first match of sub

    Exceptions
    Type Condition
    NullReferenceException

    Source cannot be null.

    StartsWith(SubString)

    Tells whether this SubString starts with the specified prefix.

    Declaration
    public bool StartsWith(SubString prefix)
    Parameters
    Type Name Description
    SubString prefix

    The pattern to compare to the beginning of this SubString.

    Returns
    Type Description
    bool

    Whether this SubString starts with the specified prefix.

    Exceptions
    Type Condition
    ArgumentNullException

    prefix cannot ne null.

    Sub(Range)

    Gets a portion of this instance.

    Declaration
    public SubString Sub(Range offsets)
    Parameters
    Type Name Description
    Range offsets

    The bounds of the subpart to extract.

    Returns
    Type Description
    SubString

    A new SubString instance.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    UtfSub(Range)

    Gets a portion of this instance, considering the unicode characters instead of chars.

    Declaration
    public SubString UtfSub(Range offsets)
    Parameters
    Type Name Description
    Range offsets

    The bounds of the subpart to extract.

    Returns
    Type Description
    SubString

    A new SubString instance.

    Operators

    implicit operator SubString(string)

    Creates a SubString instance from a full string value.

    Declaration
    public static implicit operator SubString(string input)
    Parameters
    Type Name Description
    string input

    The original string value. The resulting SubString will cover the whole value of input.

    Returns
    Type Description
    SubString

    A SubString instance covering the whole input.

    implicit operator string(SubString)

    Gets a string value from the portion of the source string of this SubString.

    Declaration
    public static implicit operator string(SubString input)
    Parameters
    Type Name Description
    SubString input

    The SubString value to convert to a string value.

    Returns
    Type Description
    string

    The string representing the value of this SubString.

    Implements

    IEquatable<T>
    IComparable<T>
    IEquatable<T>
    IComparable<T>
    IEnumerable<T>
    IEnumerable
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)