Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct Microsoft.​Extensions.​Primitives.​StringSegment
Assembly: Microsoft.Extensions.Primitives
Implemented Interfaces
An optimized representation of a substring.
Fields and Constants
public static readonly
StringSegment
Empty
A <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> for <see cref="F:System.String.Empty" /> .
Properties
public
string
Buffer
Gets the <see cref="T:System.String" /> buffer for this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
bool
HasValue
Gets whether this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> contains a valid value.
public
char
Item
public
int
Length
Gets the length of this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
int
Offset
Gets the offset within the buffer for this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
string
Value
Gets the value of this segment as a <see cref="T:System.String" /> .
Methods
public
System.​ReadOnlyMemory<​char>
AsMemory​()
Gets a <see cref="T:System.ReadOnlyMemory`1" /> from the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns The <see cref="T:System.ReadOnlyMemory`1" /> from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
System.​ReadOnlySpan<​char>
AsSpan​()
Gets a <see cref="T:System.ReadOnlySpan`1" /> from the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns The <see cref="T:System.ReadOnlySpan`1" /> from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
System.​ReadOnlySpan<​char>
AsSpan​(int start)
Gets a <see cref="T:System.ReadOnlySpan`1" /> from the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that starts
at the position specified by <paramref name="start" /> , and has the remaining length.
Returns A <see cref="T:System.ReadOnlySpan`1" /> with the remaining chars that begins at <paramref name="start" /> in
this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
start
The zero-based starting character position in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
System.​ReadOnlySpan<​char>
AsSpan​(int start,
int length)
Gets a <see cref="T:System.ReadOnlySpan`1" /> from the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that starts
at the position specified by <paramref name="start" /> , and has the specified <paramref name="length" /> .
Returns A <see cref="T:System.ReadOnlySpan`1" /> with <paramref name="length" /> that begins at
<paramref name="start" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
start
The zero-based starting character position in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
length
The number of characters in the span.
public static
int
Compare​(StringSegment a,
StringSegment b,
System.​StringComparison comparisonType)
Compares substrings of two specified <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> objects using the specified rules,
and returns an integer that indicates their relative position in the sort order.
Returns A 32-bit signed integer indicating the lexical relationship between the two comparands.
The value is negative if <paramref name="a" /> is less than <paramref name="b" /> , 0 if the two comparands are equal,
and positive if <paramref name="a" /> is greater than <paramref name="b" /> .
a
The first <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> to compare.
b
The second <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> to compare.
comparisonType
One of the enumeration values that specifies the rules for the comparison.
public
bool
EndsWith​(string text,
System.​StringComparison comparisonType)
Checks if the end of this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> matches the specified <see cref="T:System.String" /> when compared using the specified <paramref name="comparisonType" /> .
Returns <see langword="true" /> if <paramref name="text" /> matches the end of this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> ; otherwise, <see langword="false" /> .
text
The <see cref="T:System.String" /> to compare.
comparisonType
One of the enumeration values that specifies the rules to use in the comparison.
public
bool
Equals​(StringSegment other)
Indicates whether the current object is equal to another object of the same type.
Returns <see langword="true" /> if the current object is equal to <paramref name="other" /> ; otherwise, <see langword="false" /> .
other
An object to compare with this object.
public static
bool
Equals​(StringSegment a,
StringSegment b,
System.​StringComparison comparisonType)
Determines whether two specified <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> objects have the same value. A parameter specifies the culture, case, and
sort rules used in the comparison.
Returns <see langword="true" /> if the objects are equal; otherwise, <see langword="false" /> .
a
The first <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> to compare.
b
The second <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> to compare.
comparisonType
One of the enumeration values that specifies the rules for the comparison.
public
bool
Equals​(StringSegment other,
System.​StringComparison comparisonType)
Indicates whether the current object is equal to another object of the same type.
Returns <see langword="true" /> if the current object is equal to <paramref name="other" /> ; otherwise, <see langword="false" /> .
other
An object to compare with this object.
comparisonType
One of the enumeration values that specifies the rules to use in the comparison.
public
bool
Equals​(object obj)
Indicates whether the current object is equal to another object of the same type.
Returns <see langword="true" /> if the current object is equal to <paramref name="obj" /> ; otherwise, <see langword="false" /> .
obj
An object to compare with this object.
public
bool
Equals​(string text)
Checks if the specified <see cref="T:System.String" /> is equal to the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns <see langword="true" /> if the specified <see cref="T:System.String" /> is equal to the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> ; otherwise, <see langword="false" /> .
text
The <see cref="T:System.String" /> to compare with the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
bool
Equals​(string text,
System.​StringComparison comparisonType)
Checks if the specified <see cref="T:System.String" /> is equal to the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns <see langword="true" /> if the specified <see cref="T:System.String" /> is equal to the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> ; otherwise, <see langword="false" /> .
text
The <see cref="T:System.String" /> to compare with the current <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
comparisonType
One of the enumeration values that specifies the rules to use in the comparison.
public
int
GetHashCode​()
Returns a hash code for this instance.
Returns A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public
int
IndexOf​(char c)
Gets the zero-based index of the first occurrence of the character <paramref name="c" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns The zero-based index position of <paramref name="c" /> from the beginning of the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> if that character is found, or -1 if it is not.
c
The Unicode character to seek.
public
int
IndexOf​(char c,
int start)
Gets the zero-based index of the first occurrence of the character <paramref name="c" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The search starts at <paramref name="start" /> .
Returns The zero-based index position of <paramref name="c" /> from the beginning of the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> if that character is found, or -1 if it is not.
c
The Unicode character to seek.
start
The zero-based index position at which the search starts.
public
int
IndexOf​(char c,
int start,
int count)
Gets the zero-based index of the first occurrence of the character <paramref name="c" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The search starts at <paramref name="start" /> and examines a specified number of <paramref name="count" /> character positions.
Returns The zero-based index position of <paramref name="c" /> from the beginning of the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> if that character is found, or -1 if it is not.
c
The Unicode character to seek.
start
The zero-based index position at which the search starts.
count
The number of characters to examine.
public
int
IndexOfAny​(char[] anyOf)
Reports the zero-based index of the first occurrence in this instance of any character in a specified array
of Unicode characters.
Returns The zero-based index position of the first occurrence in this instance where any character in <paramref name="anyOf" />
was found; -1 if no character in <paramref name="anyOf" /> was found.
anyOf
A Unicode character array containing one or more characters to seek.
public
int
IndexOfAny​(char[] anyOf,
int startIndex)
Reports the zero-based index of the first occurrence in this instance of any character in a specified array
of Unicode characters. The search starts at a specified character position.
Returns The zero-based index position of the first occurrence in this instance where any character in <paramref name="anyOf" />
was found; -1 if no character in <paramref name="anyOf" /> was found.
anyOf
A Unicode character array containing one or more characters to seek.
startIndex
The search starting position.
public
int
IndexOfAny​(char[] anyOf,
int startIndex,
int count)
Reports the zero-based index of the first occurrence in this instance of any character in a specified array
of Unicode characters. The search starts at a specified character position and examines a specified number
of character positions.
Returns The zero-based index position of the first occurrence in this instance where any character in <paramref name="anyOf" />
was found; -1 if no character in <paramref name="anyOf" /> was found.
anyOf
A Unicode character array containing one or more characters to seek.
startIndex
The search starting position.
count
The number of character positions to examine.
public static
bool
IsNullOrEmpty​(StringSegment value)
Indicates whether the specified <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> is null or an Empty string.
value
The <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> to test.
public
int
LastIndexOf​(char value)
Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance.
Returns The zero-based index position of value if that character is found, or -1 if it is not.
value
The Unicode character to seek.
public
StringTokenizer
Split​(char[] chars)
Splits a string into <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> s that are based on the characters in an array.
Returns An <see cref="T:Microsoft.Extensions.Primitives.StringTokenizer" /> whose elements contain the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> s from this instance
that are delimited by one or more characters in <paramref name="chars" /> .
chars
A character array that delimits the substrings in this string, an empty array that
contains no delimiters, or null.
public
bool
StartsWith​(string text,
System.​StringComparison comparisonType)
Checks if the beginning of this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> matches the specified <see cref="T:System.String" /> when compared using the specified <paramref name="comparisonType" /> .
Returns <see langword="true" /> if <paramref name="text" /> matches the beginning of this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> ; otherwise, <see langword="false" /> .
text
The <see cref="T:System.String" /> to compare.
comparisonType
One of the enumeration values that specifies the rules to use in the comparison.
public
StringSegment
Subsegment​(int offset)
Retrieves a <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that represents a substring from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> starts at the position specified by <paramref name="offset" /> .
Returns A <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that begins at <paramref name="offset" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" />
whose length is the remainder.
offset
The zero-based starting character position of a substring in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
StringSegment
Subsegment​(int offset,
int length)
Retrieves a <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that represents a substring from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> starts at the position specified by <paramref name="offset" /> and has the specified <paramref name="length" /> .
Returns A <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> that is equivalent to the substring of <paramref name="length" /> that begins at <paramref name="offset" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
offset
The zero-based starting character position of a substring in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
length
The number of characters in the substring.
public
string
Substring​(int offset)
Retrieves a substring from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The substring starts at the position specified by <paramref name="offset" /> and has the remaining length.
Returns A <see cref="T:System.String" /> that is equivalent to the substring of remaining length that begins at
<paramref name="offset" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
offset
The zero-based starting character position of a substring in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
public
string
Substring​(int offset,
int length)
Retrieves a substring from this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
The substring starts at the position specified by <paramref name="offset" /> and has the specified <paramref name="length" /> .
Returns A <see cref="T:System.String" /> that is equivalent to the substring of <paramref name="length" /> that begins at
<paramref name="offset" /> in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
offset
The zero-based starting character position of a substring in this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
length
The number of characters in the substring.
public
string
ToString​()
Returns the <see cref="T:System.String" /> represented by this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> or <see cref="F:System.String.Empty" /> if the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> does not contain a value.
Returns The <see cref="T:System.String" /> represented by this <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> or <see cref="F:System.String.Empty" /> if the <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> does not contain a value.
Returns The trimmed <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns The trimmed <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
Returns The trimmed <see cref="T:Microsoft.Extensions.Primitives.StringSegment" /> .
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object