MemoryExtensions
Extension methods for Span{T}, Memory{T}, and friends.
Creates a new memory over the target array.
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new memory over the portion of the target array.
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new ReadOnlyMemory<T> over the portion of the target string.
Creates a new ReadOnlyMemory<T> over the portion of the target string.
Creates a new ReadOnlyMemory<T> over the portion of the target string.
Creates a new span over the target array.
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new span over the portion of the target array segment.
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
Creates a new span over the portion of the target array.
Creates a new readonly span over the portion of the target string.
Creates a new readonly span over the portion of the target string.
Creates a new readonly span over the portion of the target string.
Searches an entire sorted Span<T> for a value
using the specified IComparable<T> generic interface.
public static int BinarySearch<T, TComparable>(this Span<T> span, TComparable comparable) where TComparable : IComparable<T>
Searches an entire sorted Span<T> for a value
using the specified TComparable generic type.
public static int BinarySearch<T, TComparer>(this Span<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
Searches an entire sorted Span<T> for the specified value
using the specified TComparer generic type.
Searches an entire sorted ReadOnlySpan<T> for a value
using the specified IComparable<T> generic interface.
public static int BinarySearch<T, TComparable>(this ReadOnlySpan<T> span, TComparable comparable) where TComparable : IComparable<T>
Searches an entire sorted ReadOnlySpan<T> for a value
using the specified TComparable generic type.
public static int BinarySearch<T, TComparer>(this ReadOnlySpan<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
Searches an entire sorted ReadOnlySpan<T> for the specified value
using the specified TComparer generic type.
public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
Compares the specified span and other using the specified comparisonType,
and returns an integer that indicates their relative position in the sort order.
The source span.The value to compare with the source span.One of the enumeration values that determines how the span and other are compared.
public static bool Contains(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
Returns a value indicating whether the specified value occurs within the span.
The source span.The value to seek within the source span.One of the enumeration values that determines how the span and value are compared.
Copies the contents of the array into the span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
The array to copy items from.The span to copy items into.Thrown when the destination Span is shorter than the source array.
Copies the contents of the array into the memory. If the source
and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
The array to copy items from.The memory to copy items into.Thrown when the destination is shorter than the source array.
Determines whether the specified sequence appears at the end of the span.
public static bool EndsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
Determines whether the specified sequence appears at the end of the span.
public static bool EndsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
Determines whether the end of the span matches the specified value when compared using the specified comparisonType option.
public static bool Equals(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
Determines whether this span and the specified other span have the same characters
when compared using the specified comparisonType option.
The source span.The value to compare with the source span.One of the enumeration values that determines how the span and other are compared.
Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
public static int IndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
public static int IndexOf(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified value in the current span.
The source span.The value to seek within the source span.One of the enumeration values that determines how the span and value are compared.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
public static int IndexOfAny<T>(this Span<T> span, T value0, T value1, T value2) where T : IEquatable<T>
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1) where T : IEquatable<T>
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2) where T : IEquatable<T>
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
public static int IndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
Indicates whether the specified span contains only white-space characters.
Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
public static int LastIndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1, T value2) where T : IEquatable<T>
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
public static int LastIndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1) where T : IEquatable<T>
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2) where T : IEquatable<T>
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
Determines whether two sequences overlap in memory.
Determines whether two sequences overlap in memory and outputs the element offset.
Determines whether two sequences overlap in memory.
public static bool Overlaps<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other, out int elementOffset)
Determines whether two sequences overlap in memory and outputs the element offset.
Reverses the sequence of the elements in the entire span.
public static int SequenceCompareTo<T>(this Span<T> span, ReadOnlySpan<T> other) where T : IComparable<T>
Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
public static int SequenceCompareTo<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other) where T : IComparable<T>
Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
public static bool SequenceEqual<T>(this Span<T> span, ReadOnlySpan<T> other) where T : IEquatable<T>
Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
public static bool SequenceEqual<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other) where T : IEquatable<T>
Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
Determines whether the specified sequence appears at the start of the span.
public static bool StartsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value) where T : IEquatable<T>
Determines whether the specified sequence appears at the start of the span.
public static bool StartsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
Determines whether the beginning of the span matches the specified value when compared using the specified comparisonType option.
public static int ToLower(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
Copies the characters from the source span into the destination, converting each character to lowercase,
using the casing rules of the specified culture.
Copies the characters from the source span into the destination, converting each character to lowercase,
using the casing rules of the invariant culture.
public static int ToUpper(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo culture)
Copies the characters from the source span into the destination, converting each character to uppercase,
using the casing rules of the specified culture.
Copies the characters from the source span into the destination, converting each character to uppercase
using the casing rules of the invariant culture.
Removes all leading and trailing white-space characters from the span.
Removes all leading and trailing occurrences of a specified character.
Removes all leading and trailing occurrences of a set of characters specified
in a readonly span from the span.
Removes all trailing white-space characters from the span.
Removes all trailing occurrences of a specified character.
public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
Removes all trailing occurrences of a set of characters specified
in a readonly span from the span.
Removes all leading white-space characters from the span.
Removes all leading occurrences of a specified character.
public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
Removes all leading occurrences of a set of characters specified
in a readonly span from the span.