ReadOnlySpanExtensions 1.5.0

dotnet add package ReadOnlySpanExtensions --version 1.5.0
NuGet\Install-Package ReadOnlySpanExtensions -Version 1.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ReadOnlySpanExtensions" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReadOnlySpanExtensions --version 1.5.0
#r "nuget: ReadOnlySpanExtensions, 1.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ReadOnlySpanExtensions as a Cake Addin
#addin nuget:?package=ReadOnlySpanExtensions&version=1.5.0

// Install ReadOnlySpanExtensions as a Cake Tool
#tool nuget:?package=ReadOnlySpanExtensions&version=1.5.0

ReadOnlySpanExtensions (C#)

Available via Nuget: https://www.nuget.org/packages/ReadOnlySpanExtensions

Little convenience helper extension methods for slicing ReadOnlySpan (C#) via texts.
All available extension methods start with Span in their name.

Extension methods

SpanBefore

Returns all characters before the given text.

Example

span text Return value
Test1/Test2 / Test1

SpanBeforeIncluding

Returns all characters before and including the given text itself.

Example

span text Return value
Test1/Test2 / Test1/

SpanBeforeLast

Returns all characters before the last occurence of the given text.

Example

span text Return value
Test1/Test2 Test Test1/

SpanBeforeLastIncluding

Returns all characters before the last occurence of and including the given text itself.

Example

span text Return value
Test1/Test2 Test Test1/Test

SpanBeforeNth

Returns all characters before the nth occurence of the given text.

Example

span text count Return value
Test1/Test2/Test3 Test 3 Test1/Test2/

SpanBeforeNthIncluding

Returns all characters before the nth occurence of and including the given text itself.

Example

span text count Return value
Test1/Test2/Test3 Test 3 Test1/Test2/Test

SpanAfter

Returns all characters after the given text.

Example

span text Return value
Test1/Test2 / Test2

SpanAfterIncluding

Returns all characters after and including the given text itself.

Example

span text Return value
Test1/Test2 / /Test2

SpanAfterLast

Returns all characters after the last occurence of the given text.

Example

span text Return value
Test1/Test2 Test 2

SpanAfterLastIncluding

Returns all characters after the last occurence of and including the given text itself.

Example

span text Return value
Test1/Test2 Test Test2

SpanAfterNth

Returns all characters after the nth occurence of the given text.

Example

span text count Return value
Test1/Test2/Test3 Test 3 3

SpanAfterNthIncluding

Returns all characters after the nth occurence of and including the given text itself.

Example

span text count Return value
Test1/Test2/Test3 Test 3 Test3

SpanBetween

Returns all characters between the given start and end text.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> Dummy1

SpanBetweenIncluding

Returns all characters between and including the given start and end text themselves.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> <td>Dummy1</td>

SpanBetweenOuter

Returns all characters between the first occurrence of the given start and the last occurrence of the given end text.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> Dummy1</td><td>Dummy2

SpanBetweenOuterIncluding

Returns all characters between the first occurrence of the given start and the last occurrence of the given end text and including the texts themselves.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> <td>Dummy1</td><td>Dummy2</td>

SpanBetweenLast

Returns all characters between the last occurence of the given start and end text.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> Dummy2

SpanBetweenLastIncluding

Returns all characters between the last occurence of the given start and end text and including the texts themselves.

Example

span startText endText Return value
<td>Dummy1</td><td>Dummy2</td> <td> </td> <td>Dummy2</td>

SpanBetweenNth

Returns all characters between the nth occurence of the given start and end text.

Example

span startText endText count Return value
<td>Dummy1</td><td>Dummy2</td><td>Dummy3</td> <td> </td> 2 Dummy2

SpanBetweenNthIncluding

Returns all characters between the nth occurence of the given start and end text and including the texts themselves.

Example

span startText endText count Return value
<td>Dummy1</td><td>Dummy2</td><td>Dummy3</td> <td> </td> 2 <td>Dummy2</td>

SpanCount

Returns the count of the given text.

Example

span text Return value
Test1/Test2/Test3 Test 3

SpanPairSurrounding (for single text)

Returns both spans before and after the given text.

Example

span text Return value
Test1/Test2 / Test1 / Test2

SpanPairSurrounding (for start/end text)

Returns both spans before the given start and after the end text.

Example

span startText endText Return value
<table><tr><td>Dummy</td></tr></table> <tr> </tr> <table> / </table>

SpanPairSurroundingIncluding

Returns both spans before the given start and after the end text including the texts themselves.

Example

span startText endText Return value
<table><tr><td>Dummy</td></tr></table> <tr> </tr> <table><tr> / </tr></table>

SpanPairSurroundingOuter

Returns both spans before the first occurrence of the given start and after the last occurrence of the end text.

Example

span startText endText Return value
<table><tr><td>Dummy1</td><td>Dummy2</td></tr></table> <td> </td> <table><tr> / </tr></table>

SpanPairSurroundingOuterIncluding

Returns both spans before the first occurrence of the given start and after the last occurrence of the end text including the texts themselves.

Example

span startText endText Return value
<table><tr><td>Dummy1</td><td>Dummy2</td></tr></table> <td> </td> <table><tr><td> / </td></tr></table>

Further remarks

See the tests for further examples.

In general all methods have an optional startPos parameter in case searching should not start at 0 (beginning). Beware that for the SpanBeforeXXX methods this only influences the search position but not the outcome. Meaning the characters before startPos are included in a possible result.

Furthermore all methods have an optional stringComparison parameter to configure the culture & case sensitivity behaviour. The default value is Ordinal. Meaning compare strings using ordinal (binary) sort rules.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 132 8/22/2023
1.4.0 118 8/13/2023
1.3.1 139 7/29/2023
1.3.0 137 7/29/2023
1.2.1 137 7/29/2023
1.2.0 131 7/26/2023
1.1.0 140 7/24/2023
1.0.1 137 7/24/2023
1.0.0 140 7/23/2023

v1.5.0
- Added SpanBetweenLast.

v1.4.0
- Added SpanBetweenNth & SpanPairSurrounding (for single text).

v1.3.1
- Fixed README typo.

v1.3.0
- Added SpanPairSurrounding.

v1.2.1
- Validity check for SpanCount.

v1.2.0
- Added SpanCount.

v1.1.0
- Added optional StringComparison parameter.

v1.0.1
- Modified & fixed README for NuGet.

v1.0.0
- Initial release.