Skip to main content

StringSpanExtensions

Helpful extensions on ReadOnlySpan<char> Previous extensions on StringSegment available from: https://gist.github.com/mythz/9825689f0db7464d1d541cb62954614c

Assembly: ServiceStack.Text.dll
View Source
Declaration
public static class StringSpanExtensions

Methods

Value(ReadOnlySpan<Char>)

Returns null if Length == 0, string.Empty if value[0] == NonWidthWhitespace, otherwise returns value.ToString()

View Source
Declaration
public static string Value(this ReadOnlySpan<char> value)
Returns

System.String

Parameters
TypeName
ReadOnlySpan<System.Char>value

IsNullOrEmpty(ReadOnlySpan<Char>)

View Source
Declaration
public static bool IsNullOrEmpty(this ReadOnlySpan<char> value)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value

IsNullOrWhiteSpace(ReadOnlySpan<Char>)

View Source
Declaration
public static bool IsNullOrWhiteSpace(this ReadOnlySpan<char> value)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value

GetChar(ReadOnlySpan<Char>, Int32)

View Source
Declaration
[Obsolete("Use value[index]")]
public static char GetChar(this ReadOnlySpan<char> value, int index)
Returns

System.Char

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32index

Substring(ReadOnlySpan<Char>, Int32)

View Source
Declaration
public static string Substring(this ReadOnlySpan<char> value, int pos)
Returns

System.String

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32pos

Substring(ReadOnlySpan<Char>, Int32, Int32)

View Source
Declaration
public static string Substring(this ReadOnlySpan<char> value, int pos, int length)
Returns

System.String

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32pos
System.Int32length

CompareIgnoreCase(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

View Source
Declaration
public static bool CompareIgnoreCase(this ReadOnlySpan<char> value, ReadOnlySpan<char> text)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
ReadOnlySpan<System.Char>text

FromCsvField(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> FromCsvField(this ReadOnlySpan<char> text)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>text

ParseBoolean(ReadOnlySpan<Char>)

View Source
Declaration
public static bool ParseBoolean(this ReadOnlySpan<char> value)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value

TryParseBoolean(ReadOnlySpan<Char>, out Boolean)

View Source
Declaration
public static bool TryParseBoolean(this ReadOnlySpan<char> value, out bool result)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Booleanresult

TryParseDecimal(ReadOnlySpan<Char>, out Decimal)

View Source
Declaration
public static bool TryParseDecimal(this ReadOnlySpan<char> value, out decimal result)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Decimalresult

TryParseFloat(ReadOnlySpan<Char>, out Single)

View Source
Declaration
public static bool TryParseFloat(this ReadOnlySpan<char> value, out float result)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Singleresult

TryParseDouble(ReadOnlySpan<Char>, out Double)

View Source
Declaration
public static bool TryParseDouble(this ReadOnlySpan<char> value, out double result)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Doubleresult

ParseDecimal(ReadOnlySpan<Char>)

View Source
Declaration
public static decimal ParseDecimal(this ReadOnlySpan<char> value)
Returns

System.Decimal

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseDecimal(ReadOnlySpan<Char>, Boolean)

View Source
Declaration
public static decimal ParseDecimal(this ReadOnlySpan<char> value, bool allowThousands)
Returns

System.Decimal

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.BooleanallowThousands

ParseFloat(ReadOnlySpan<Char>)

View Source
Declaration
public static float ParseFloat(this ReadOnlySpan<char> value)
Returns

System.Single

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseDouble(ReadOnlySpan<Char>)

View Source
Declaration
public static double ParseDouble(this ReadOnlySpan<char> value)
Returns

System.Double

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseSByte(ReadOnlySpan<Char>)

View Source
Declaration
public static sbyte ParseSByte(this ReadOnlySpan<char> value)
Returns

System.SByte

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseByte(ReadOnlySpan<Char>)

View Source
Declaration
public static byte ParseByte(this ReadOnlySpan<char> value)
Returns

System.Byte

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseInt16(ReadOnlySpan<Char>)

View Source
Declaration
public static short ParseInt16(this ReadOnlySpan<char> value)
Returns

System.Int16

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseUInt16(ReadOnlySpan<Char>)

View Source
Declaration
public static ushort ParseUInt16(this ReadOnlySpan<char> value)
Returns

System.UInt16

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseInt32(ReadOnlySpan<Char>)

View Source
Declaration
public static int ParseInt32(this ReadOnlySpan<char> value)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseUInt32(ReadOnlySpan<Char>)

View Source
Declaration
public static uint ParseUInt32(this ReadOnlySpan<char> value)
Returns

System.UInt32

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseInt64(ReadOnlySpan<Char>)

View Source
Declaration
public static long ParseInt64(this ReadOnlySpan<char> value)
Returns

System.Int64

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseUInt64(ReadOnlySpan<Char>)

View Source
Declaration
public static ulong ParseUInt64(this ReadOnlySpan<char> value)
Returns

System.UInt64

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseGuid(ReadOnlySpan<Char>)

View Source
Declaration
public static Guid ParseGuid(this ReadOnlySpan<char> value)
Returns

System.Guid

Parameters
TypeName
ReadOnlySpan<System.Char>value

ParseSignedInteger(ReadOnlySpan<Char>)

View Source
Declaration
public static object ParseSignedInteger(this ReadOnlySpan<char> value)
Returns

System.Object

Parameters
TypeName
ReadOnlySpan<System.Char>value

TryReadLine(ReadOnlySpan<Char>, out ReadOnlySpan<Char>, ref Int32)

View Source
Declaration
public static bool TryReadLine(this ReadOnlySpan<char> text, out ReadOnlySpan<char> line, ref int startIndex)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>text
ReadOnlySpan<System.Char>line
System.Int32startIndex

TryReadPart(ReadOnlySpan<Char>, String, out ReadOnlySpan<Char>, ref Int32)

View Source
Declaration
public static bool TryReadPart(this ReadOnlySpan<char> text, string needle, out ReadOnlySpan<char> part, ref int startIndex)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>text
System.Stringneedle
ReadOnlySpan<System.Char>part
System.Int32startIndex

Advance(ReadOnlySpan<Char>, Int32)

View Source
Declaration
public static ReadOnlySpan<char> Advance(this ReadOnlySpan<char> text, int to)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>text
System.Int32to

AdvancePastWhitespace(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> AdvancePastWhitespace(this ReadOnlySpan<char> literal)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>literal

AdvancePastChar(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static ReadOnlySpan<char> AdvancePastChar(this ReadOnlySpan<char> literal, char delim)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>literal
System.Chardelim

Subsegment(ReadOnlySpan<Char>, Int32)

View Source
Declaration
[Obsolete("Use Slice()")]
public static ReadOnlySpan<char> Subsegment(this ReadOnlySpan<char> text, int startPos)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>text
System.Int32startPos

Subsegment(ReadOnlySpan<Char>, Int32, Int32)

View Source
Declaration
[Obsolete("Use Slice()")]
public static ReadOnlySpan<char> Subsegment(this ReadOnlySpan<char> text, int startPos, int length)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>text
System.Int32startPos
System.Int32length

LeftPart(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> strVal, char needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle

LeftPart(ReadOnlySpan<Char>, String)

View Source
Declaration
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> strVal, string needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle

RightPart(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static ReadOnlySpan<char> RightPart(this ReadOnlySpan<char> strVal, char needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle

RightPart(ReadOnlySpan<Char>, String)

View Source
Declaration
public static ReadOnlySpan<char> RightPart(this ReadOnlySpan<char> strVal, string needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle

LastLeftPart(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static ReadOnlySpan<char> LastLeftPart(this ReadOnlySpan<char> strVal, char needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle

LastLeftPart(ReadOnlySpan<Char>, String)

View Source
Declaration
public static ReadOnlySpan<char> LastLeftPart(this ReadOnlySpan<char> strVal, string needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle

LastRightPart(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static ReadOnlySpan<char> LastRightPart(this ReadOnlySpan<char> strVal, char needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle

LastRightPart(ReadOnlySpan<Char>, String)

View Source
Declaration
public static ReadOnlySpan<char> LastRightPart(this ReadOnlySpan<char> strVal, string needle)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle

SplitOnFirst(ReadOnlySpan<Char>, Char, out ReadOnlySpan<Char>, out ReadOnlySpan<Char>)

View Source
Declaration
public static void SplitOnFirst(this ReadOnlySpan<char> strVal, char needle, out ReadOnlySpan<char> first, out ReadOnlySpan<char> last)
Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle
ReadOnlySpan<System.Char>first
ReadOnlySpan<System.Char>last

SplitOnFirst(ReadOnlySpan<Char>, String, out ReadOnlySpan<Char>, out ReadOnlySpan<Char>)

View Source
Declaration
public static void SplitOnFirst(this ReadOnlySpan<char> strVal, string needle, out ReadOnlySpan<char> first, out ReadOnlySpan<char> last)
Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle
ReadOnlySpan<System.Char>first
ReadOnlySpan<System.Char>last

SplitOnLast(ReadOnlySpan<Char>, Char, out ReadOnlySpan<Char>, out ReadOnlySpan<Char>)

View Source
Declaration
public static void SplitOnLast(this ReadOnlySpan<char> strVal, char needle, out ReadOnlySpan<char> first, out ReadOnlySpan<char> last)
Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Charneedle
ReadOnlySpan<System.Char>first
ReadOnlySpan<System.Char>last

SplitOnLast(ReadOnlySpan<Char>, String, out ReadOnlySpan<Char>, out ReadOnlySpan<Char>)

View Source
Declaration
public static void SplitOnLast(this ReadOnlySpan<char> strVal, string needle, out ReadOnlySpan<char> first, out ReadOnlySpan<char> last)
Parameters
TypeName
ReadOnlySpan<System.Char>strVal
System.Stringneedle
ReadOnlySpan<System.Char>first
ReadOnlySpan<System.Char>last

WithoutExtension(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> WithoutExtension(this ReadOnlySpan<char> filePath)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>filePath

GetExtension(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> GetExtension(this ReadOnlySpan<char> filePath)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>filePath

ParentDirectory(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> ParentDirectory(this ReadOnlySpan<char> filePath)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>filePath

TrimEnd(ReadOnlySpan<Char>, Char[])

View Source
Declaration
public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> value, params char[] trimChars)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Char[]trimChars

SafeSlice(ReadOnlySpan<Char>, Int32)

View Source
Declaration
public static ReadOnlySpan<char> SafeSlice(this ReadOnlySpan<char> value, int startIndex)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32startIndex

SafeSlice(ReadOnlySpan<Char>, Int32, Int32)

View Source
Declaration
public static ReadOnlySpan<char> SafeSlice(this ReadOnlySpan<char> value, int startIndex, int length)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32startIndex
System.Int32length

SubstringWithEllipsis(ReadOnlySpan<Char>, Int32, Int32)

View Source
Declaration
public static string SubstringWithEllipsis(this ReadOnlySpan<char> value, int startIndex, int length)
Returns

System.String

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32startIndex
System.Int32length

IndexOf(ReadOnlySpan<Char>, String)

View Source
Declaration
public static int IndexOf(this ReadOnlySpan<char> value, string other)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

IndexOf(ReadOnlySpan<Char>, String, Int32)

View Source
Declaration
public static int IndexOf(this ReadOnlySpan<char> value, string needle, int start)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringneedle
System.Int32start

LastIndexOf(ReadOnlySpan<Char>, String)

View Source
Declaration
public static int LastIndexOf(this ReadOnlySpan<char> value, string other)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

LastIndexOf(ReadOnlySpan<Char>, String, Int32)

View Source
Declaration
public static int LastIndexOf(this ReadOnlySpan<char> value, string needle, int start)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringneedle
System.Int32start

EqualTo(ReadOnlySpan<Char>, String)

View Source
Declaration
public static bool EqualTo(this ReadOnlySpan<char> value, string other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

EqualTo(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

View Source
Declaration
public static bool EqualTo(this ReadOnlySpan<char> value, ReadOnlySpan<char> other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
ReadOnlySpan<System.Char>other

EqualsOrdinal(ReadOnlySpan<Char>, String)

View Source
Declaration
public static bool EqualsOrdinal(this ReadOnlySpan<char> value, string other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

StartsWith(ReadOnlySpan<Char>, String)

View Source
Declaration
public static bool StartsWith(this ReadOnlySpan<char> value, string other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

StartsWith(ReadOnlySpan<Char>, String, StringComparison)

View Source
Declaration
public static bool StartsWith(this ReadOnlySpan<char> value, string other, StringComparison comparison)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother
System.StringComparisoncomparison

EndsWith(ReadOnlySpan<Char>, String, StringComparison)

View Source
Declaration
public static bool EndsWith(this ReadOnlySpan<char> value, string other, StringComparison comparison)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother
System.StringComparisoncomparison

EndsWith(ReadOnlySpan<Char>, String)

View Source
Declaration
public static bool EndsWith(this ReadOnlySpan<char> value, string other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Stringother

EqualsIgnoreCase(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

View Source
Declaration
public static bool EqualsIgnoreCase(this ReadOnlySpan<char> value, ReadOnlySpan<char> other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
ReadOnlySpan<System.Char>other

StartsWithIgnoreCase(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

View Source
Declaration
public static bool StartsWithIgnoreCase(this ReadOnlySpan<char> value, ReadOnlySpan<char> other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
ReadOnlySpan<System.Char>other

EndsWithIgnoreCase(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

View Source
Declaration
public static bool EndsWithIgnoreCase(this ReadOnlySpan<char> value, ReadOnlySpan<char> other)
Returns

System.Boolean

Parameters
TypeName
ReadOnlySpan<System.Char>value
ReadOnlySpan<System.Char>other

WriteAsync(Stream, ReadOnlySpan<Char>, CancellationToken)

View Source
Declaration
public static Task WriteAsync(this Stream stream, ReadOnlySpan<char> value, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task

Parameters
TypeName
System.IO.Streamstream
ReadOnlySpan<System.Char>value
System.Threading.CancellationTokentoken

SafeSubstring(ReadOnlySpan<Char>, Int32)

View Source
Declaration
public static ReadOnlySpan<char> SafeSubstring(this ReadOnlySpan<char> value, int startIndex)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32startIndex

SafeSubstring(ReadOnlySpan<Char>, Int32, Int32)

View Source
Declaration
public static ReadOnlySpan<char> SafeSubstring(this ReadOnlySpan<char> value, int startIndex, int length)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Int32startIndex
System.Int32length

Append(StringBuilder, ReadOnlySpan<Char>)

View Source
Declaration
public static StringBuilder Append(this StringBuilder sb, ReadOnlySpan<char> value)
Returns

System.Text.StringBuilder

Parameters
TypeName
System.Text.StringBuildersb
ReadOnlySpan<System.Char>value

ParseBase64(ReadOnlySpan<Char>)

View Source
Declaration
public static byte[] ParseBase64(this ReadOnlySpan<char> value)
Returns

System.Byte[]

Parameters
TypeName
ReadOnlySpan<System.Char>value

ToUtf8(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlyMemory<byte> ToUtf8(this ReadOnlySpan<char> value)
Returns

ReadOnlyMemory<System.Byte>

Parameters
TypeName
ReadOnlySpan<System.Char>value

FromUtf8(ReadOnlySpan<Byte>)

View Source
Declaration
public static ReadOnlyMemory<char> FromUtf8(this ReadOnlySpan<byte> value)
Returns

ReadOnlyMemory<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Byte>value

ToUtf8Bytes(ReadOnlySpan<Char>)

View Source
Declaration
public static byte[] ToUtf8Bytes(this ReadOnlySpan<char> value)
Returns

System.Byte[]

Parameters
TypeName
ReadOnlySpan<System.Char>value

FromUtf8Bytes(ReadOnlySpan<Byte>)

View Source
Declaration
public static string FromUtf8Bytes(this ReadOnlySpan<byte> value)
Returns

System.String

Parameters
TypeName
ReadOnlySpan<System.Byte>value

ToStringList(IEnumerable<ReadOnlyMemory<Char>>)

View Source
Declaration
public static List<string> ToStringList(this IEnumerable<ReadOnlyMemory<char>> from)
Returns

System.Collections.Generic.List<System.String>

Parameters
TypeName
System.Collections.Generic.IEnumerable<ReadOnlyMemory<System.Char>>from

CountOccurrencesOf(ReadOnlySpan<Char>, Char)

View Source
Declaration
public static int CountOccurrencesOf(this ReadOnlySpan<char> value, char needle)
Returns

System.Int32

Parameters
TypeName
ReadOnlySpan<System.Char>value
System.Charneedle

WithoutBom(ReadOnlySpan<Char>)

View Source
Declaration
public static ReadOnlySpan<char> WithoutBom(this ReadOnlySpan<char> value)
Returns

ReadOnlySpan<System.Char>

Parameters
TypeName
ReadOnlySpan<System.Char>value

WithoutBom(ReadOnlySpan<Byte>)

View Source
Declaration
public static ReadOnlySpan<byte> WithoutBom(this ReadOnlySpan<byte> value)
Returns

ReadOnlySpan<System.Byte>

Parameters
TypeName
ReadOnlySpan<System.Byte>value