StringSegment Struct

An optimized representation of a substring.

Namespace
Microsoft.Extensions.Primitives
Assemblies
  • Microsoft.Extensions.Primitives

Syntax

public struct StringSegment : IEquatable<StringSegment>, IEquatable<string>
struct Microsoft.Extensions.Primitives.StringSegment

Constructors

StringSegment(System.String)

Initializes an instance of the Microsoft.Extensions.Primitives.StringSegment struct.

Arguments:buffer (System.String) – The original System.String. The Microsoft.Extensions.Primitives.StringSegment includes the whole System.String.
public StringSegment(string buffer)
StringSegment(System.String, System.Int32, System.Int32)

Initializes an instance of the Microsoft.Extensions.Primitives.StringSegment struct.

Arguments:
  • buffer (System.String) – The original System.String used as buffer.
  • offset (System.Int32) – The offset of the segment within the <em>buffer</em>.
  • length (System.Int32) – The length of the segment.
public StringSegment(string buffer, int offset, int length)

Properties

Microsoft.Extensions.Primitives.StringSegment.Buffer

Gets the System.String buffer for this Microsoft.Extensions.Primitives.StringSegment.

Return type:System.String
public string Buffer { get; }
Microsoft.Extensions.Primitives.StringSegment.HasValue

Gets whether or not this Microsoft.Extensions.Primitives.StringSegment contains a valid value.

Return type:System.Boolean
public bool HasValue { get; }
Microsoft.Extensions.Primitives.StringSegment.Length

Gets the length of this Microsoft.Extensions.Primitives.StringSegment.

Return type:System.Int32
public int Length { get; }
Microsoft.Extensions.Primitives.StringSegment.Offset

Gets the offset within the buffer for this Microsoft.Extensions.Primitives.StringSegment.

Return type:System.Int32
public int Offset { get; }
Microsoft.Extensions.Primitives.StringSegment.Value

Gets the value of this segment as a System.String.

Return type:System.String
public string Value { get; }

Operators

Equality(Microsoft.Extensions.Primitives.StringSegment, Microsoft.Extensions.Primitives.StringSegment)

Checks if two specified Microsoft.Extensions.Primitives.StringSegment have the same value.

Arguments:
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if the value of <em>left</em> is the same as the value of <em>right</em>; otherwise, <pre><code>false</code></pre>.

public static bool operator ==(StringSegment left, StringSegment right)
Inequality(Microsoft.Extensions.Primitives.StringSegment, Microsoft.Extensions.Primitives.StringSegment)

Checks if two specified Microsoft.Extensions.Primitives.StringSegment have different values.

Arguments:
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if the value of <em>left</em> is different from the value of <em>right</em>; otherwise, <pre><code>false</code></pre>.

public static bool operator !=(StringSegment left, StringSegment right)

Methods

EndsWith(System.String, System.StringComparison)

Checks if the end of this Microsoft.Extensions.Primitives.StringSegment matches the specified System.String when compared using the specified <em>comparisonType</em>.

Arguments:
  • text (System.String) – The System.Stringto compare.
  • comparisonType (System.StringComparison) – One of the enumeration values that specifies the rules to use in the comparison.
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if <em>text</em> matches the end of this Microsoft.Extensions.Primitives.StringSegment; otherwise, <pre><code>false</code></pre>.

public bool EndsWith(string text, StringComparison comparisonType)
Equals(Microsoft.Extensions.Primitives.StringSegment)

Indicates whether the current object is equal to another object of the same type.

Arguments:other (Microsoft.Extensions.Primitives.StringSegment) – An object to compare with this object.
Return type:System.Boolean
Returns:<pre> <code>true</code> </pre> if the current object is equal to the other parameter; otherwise, <pre><code>false</code></pre>.
public bool Equals(StringSegment other)
Equals(Microsoft.Extensions.Primitives.StringSegment, System.StringComparison)

Indicates whether the current object is equal to another object of the same type.

Arguments:
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if the current object is equal to the other parameter; otherwise, <pre><code>false</code></pre>.

public bool Equals(StringSegment other, StringComparison comparisonType)
Equals(System.Object)
Return type:System.Boolean
public override bool Equals(object obj)
Equals(System.String)

Checks if the specified System.String is equal to the current Microsoft.Extensions.Primitives.StringSegment.

Arguments:text (System.String) – The System.String to compare with the current Microsoft.Extensions.Primitives.StringSegment.
Return type:System.Boolean
Returns:<pre> <code>true</code> </pre> if the specified System.String is equal to the current Microsoft.Extensions.Primitives.StringSegment; otherwise, <pre><code>false</code></pre>.
public bool Equals(string text)
Equals(System.String, System.StringComparison)

Checks if the specified System.String is equal to the current Microsoft.Extensions.Primitives.StringSegment.

Arguments:
  • text (System.String) – The System.String to compare with the current Microsoft.Extensions.Primitives.StringSegment.
  • comparisonType (System.StringComparison) – One of the enumeration values that specifies the rules to use in the comparison.
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if the specified System.String is equal to the current Microsoft.Extensions.Primitives.StringSegment; otherwise, <pre><code>false</code></pre>.

public bool Equals(string text, StringComparison comparisonType)
GetHashCode()
Return type:System.Int32
public override int GetHashCode()
IndexOf(System.Char)

Gets the zero-based index of the first occurrence of the character <em>c</em> in this Microsoft.Extensions.Primitives.StringSegment.

Arguments:c (System.Char) – The Unicode character to seek.
Return type:System.Int32
Returns:The zero-based index position of <em>c</em> from the beginning of the Microsoft.Extensions.Primitives.StringSegment if that character is found, or -1 if it is not.
public int IndexOf(char c)
IndexOf(System.Char, System.Int32)

Gets the zero-based index of the first occurrence of the character <em>c</em> in this Microsoft.Extensions.Primitives.StringSegment. The search starts at <em>start</em>.

Arguments:
  • c (System.Char) – The Unicode character to seek.
  • start (System.Int32) – The zero-based index position at which the search starts.
Return type:

System.Int32

Returns:

The zero-based index position of <em>c</em> from the beginning of the Microsoft.Extensions.Primitives.StringSegment if that character is found, or -1 if it is not.

public int IndexOf(char c, int start)
IndexOf(System.Char, System.Int32, System.Int32)

Gets the zero-based index of the first occurrence of the character <em>c</em> in this Microsoft.Extensions.Primitives.StringSegment. The search starts at <em>start</em> and examines a specified number of <em>count</em> character positions.

Arguments:
  • c (System.Char) – The Unicode character to seek.
  • start (System.Int32) – The zero-based index position at which the search starts.
  • count (System.Int32) – The number of characters to examine.
Return type:

System.Int32

Returns:

The zero-based index position of <em>c</em> from the beginning of the Microsoft.Extensions.Primitives.StringSegment if that character is found, or -1 if it is not.

public int IndexOf(char c, int start, int count)
StartsWith(System.String, System.StringComparison)

Checks if the beginning of this Microsoft.Extensions.Primitives.StringSegment matches the specified System.String when compared using the specified <em>comparisonType</em>.

Arguments:
  • text (System.String) – The System.Stringto compare.
  • comparisonType (System.StringComparison) – One of the enumeration values that specifies the rules to use in the comparison.
Return type:

System.Boolean

Returns:

<pre> <code>true</code> </pre> if <em>text</em> matches the beginning of this Microsoft.Extensions.Primitives.StringSegment; otherwise, <pre><code>false</code></pre>.

public bool StartsWith(string text, StringComparison comparisonType)
Subsegment(System.Int32, System.Int32)

Retrieves a Microsoft.Extensions.Primitives.StringSegment that represents a substring from this Microsoft.Extensions.Primitives.StringSegment. The Microsoft.Extensions.Primitives.StringSegment starts at the position specified by <em>offset</em> and has the specified <em>length</em>.

Arguments:
Return type:

Microsoft.Extensions.Primitives.StringSegment

Returns:

A Microsoft.Extensions.Primitives.StringSegment that is equivalent to the substring of length <em>length</em> that begins at <em>offset</em> in this Microsoft.Extensions.Primitives.StringSegment

public StringSegment Subsegment(int offset, int length)
Substring(System.Int32, System.Int32)

Retrieves a substring from this Microsoft.Extensions.Primitives.StringSegment. The substring starts at the position specified by <em>offset</em> and has the specified <em>length</em>.

Arguments:
Return type:

System.String

Returns:

A System.String that is equivalent to the substring of length <em>length</em> that begins at <em>offset</em> in this Microsoft.Extensions.Primitives.StringSegment

public string Substring(int offset, int length)
ToString()

Returns the System.String represented by this Microsoft.Extensions.Primitives.StringSegment or <pre><code>String.Empty</code></pre> if the Microsoft.Extensions.Primitives.StringSegment does not contain a value.

Return type:System.String
Returns:The System.String represented by this Microsoft.Extensions.Primitives.StringSegment or <pre><code>String.Empty</code></pre> if the Microsoft.Extensions.Primitives.StringSegment does not contain a value.
public override string ToString()
Trim()

Removes all leading and trailing whitespaces.

Return type:Microsoft.Extensions.Primitives.StringSegment
Returns:The trimmed Microsoft.Extensions.Primitives.StringSegment.
public StringSegment Trim()
TrimEnd()

Removes all trailing whitespaces.

Return type:Microsoft.Extensions.Primitives.StringSegment
Returns:The trimmed Microsoft.Extensions.Primitives.StringSegment.
public StringSegment TrimEnd()
TrimStart()

Removes all leading whitespaces.

Return type:Microsoft.Extensions.Primitives.StringSegment
Returns:The trimmed Microsoft.Extensions.Primitives.StringSegment.
public StringSegment TrimStart()