Open.Text
10.0.2
dotnet add package Open.Text --version 10.0.2
NuGet\Install-Package Open.Text -Version 10.0.2
<PackageReference Include="Open.Text" Version="10.0.2" />
<PackageVersion Include="Open.Text" Version="10.0.2" />
<PackageReference Include="Open.Text" />
paket add Open.Text --version 10.0.2
#r "nuget: Open.Text, 10.0.2"
#:package Open.Text@10.0.2
#addin nuget:?package=Open.Text&version=10.0.2
#tool nuget:?package=Open.Text&version=10.0.2
Open.Text
A set of useful extensions for working with strings, string-segments, spans, enums, and value formatting.
Features
- Avoids allocation wherever possible.
- v3.x is a major overhaul with much improved methods and expanded tests and coverage.
- v4.x favored use of
Microsoft.Extensions.Primitives.StringSegmentsfor string manipulation. - NEW: Zero-allocation
*NoAllocmethods available in the separateOpen.Text.ZLinqpackage! - NEW: Roslyn analyzers to detect inefficient string patterns and suggest modern alternatives!
π Benchmark Summary
Comparing string.Split() (BCL) vs SplitAsSegments (IEnumerable) vs SplitAsSegmentsNoAlloc (ValueEnumerable via ZLinq):
| Category | Method | Time | Allocated |
|---|---|---|---|
| Count | BCL Split + LINQ Count | 46.9 ns | 256 B |
| SplitAsSegments + LINQ Count | 61.9 ns | 88 B | |
| SplitAsSegmentsNoAlloc + ZLinq Count | 55.3 ns | 0 B β | |
| LINQ-Chain | SplitAsSegmentsNoAlloc + ZLinq | 50.8 ns | 0 B β |
| BCL + System.Linq | 65.5 ns | 304 B | |
| SplitAsSegments + System.Linq | 104.4 ns | 152 B | |
| Large-Foreach | BCL Split (1000 items) | 7,342 ns | 47,952 B |
| SplitAsSegments (1000 items) | 11,740 ns | 88 B | |
| SplitAsSegmentsNoAlloc (1000 items) | 11,557 ns | 0 B β | |
| Small-Foreach | BCL Split | 42.5 ns | 256 B |
| SplitAsSegmentsNoAlloc | 45.6 ns | 0 B β | |
| SplitAsSegments | 72.4 ns | 88 B | |
| Seq-Split | SplitAsSegmentsNoAlloc(string) | 177.6 ns | 0 B β |
| SplitAsSegments(string) | 215.2 ns | 128 B | |
| BCL Split(string) | 227.1 ns | 696 B |
Key Takeaway: The
SplitAsSegmentsNoAllocmethods achieve zero heap allocations when iteratingStringSegmentvaluesβideal for high-throughput scenarios where GC pressure matters.Note: Regex-based split methods have unavoidable
Matchobject allocations.
Open.Text.ZLinq - Zero-Allocation Extension Package
For scenarios requiring true zero-allocation string operations, install the companion package:
dotnet add package Open.Text.ZLinq
This package provides *NoAlloc extension methods that return ZLinq ValueEnumerable<TEnumerator, T> structs instead of heap-allocated enumerables. These methods integrate seamlessly with ZLinq for zero-allocation LINQ operations.
Available Methods
SplitAsSegmentsNoAlloc(char)- Split by characterSplitAsSegmentsNoAlloc(string)- Split by string sequenceSplitAsSegmentsNoAlloc(Regex)- Split by regex patternJoinNoAlloc(...)- Join segments with separatorReplaceNoAlloc(...)/ReplaceAsSegmentsNoAlloc(...)- Replace sequencesAsSegmentsNoAlloc(Regex)- Get regex matches as segments
Example
using Open.Text;
using ZLinq;
// Zero-allocation split and filter
var count = "a,b,c,d,e"
.SplitAsSegmentsNoAlloc(',')
.Where(s => s.Length > 0)
.Count(); // No heap allocations!
π Roslyn Analyzers
Open.Text now includes Roslyn analyzers that help you write more efficient code by detecting common string manipulation anti-patterns and suggesting better alternatives using spans and string segments.
Installation
dotnet add package Open.Text.Analyzers
What it does
The analyzers detect patterns like:
.Substring()β suggests.AsSpan()or span slicing.Split()β suggests.SplitAsSegments()or.SplitToEnumerable()to reduce allocations.Split()[0]β suggests.FirstSplit()to avoid array allocation- String concatenation in loops β suggests
StringBuilder .Trim().Equals()β suggests.TrimEquals()to avoid intermediate string
See the Analyzers README for complete documentation.
Regex Extensions
ReadOnlySpan<char> Capture.AsSpan()
Enumerable<StringSegment> Regex.AsSegments(string input)
string GroupCollection.GetValue(string groupName)
ReadOnlySpan<char> GroupCollection.GetValueSpan(string groupName)
IEnumerable<StringSegment> string.Split(Regex pattern)
String vs Span Equality
Optimized .Equals(...) extension methods for comparing spans and strings.
String & Span Splitting
SplitToEnumerable
Returns each string segment of the split through an enumerable instead of all at once in an array.
SplitAsMemory
Produces an enumerable where each segment is yielded as a ReadOnlyMemory<char>.
SplitAsSegment
Produces an enumerable where each segment is yielded as a StringSegment.
Trimming
TrimStartPattern & TrimEndPattern
Similar to their character trimming counterparts, these methods can trim sequences of characters or regular expression patterns.
StringBuilder Extensions
Extensions for:
- adding segments with separators.
- adding spans without creating a string first.
- converting enumerables to a
StringBuilder.
StringSegment Extensions
Extensions for:
.Trim(char)and.Trim(ReadOnlySpan<char>).- finding and pivoting from sequences without allocation.
StringComparable & SpanComparable Extensions
if(myString.AsCaseInsensitive()=="HELLO!") { }
instead of
if(myString.Equals("HELLO!", StringComparison.OrdinalIgnoreCase)) { }
EnumValue<TEnum> & EnumValueIgnoreCase<TEnum>
Implicit conversion makes it easy. Optimized methods make it fast.
Consider the following:
enum Greek { Alpha, Beta, Gamma }
void DoSomethingWithGreek(Greek value) { }
DoSomethingWithGreek(Greek.Alpha);
It's nice that Greek is an enum because it won't be null, and it has to be one of the values.
But what if you want to write a single function that will take an Greek or a string?
This gets problematic as the string value has to be parsed and you'll likely need an overload.
EnumValue<TEnum> solves this problem:
enum Greek { Alpha, Beta, Gamma }
void DoSomethingWithGreek(EnumValue<Greek> value) { }
// Both work fine.
DoSomethingWithGreek("Alpha");
DoSomethingWithGreek(Greek.Alpha);
// Throws an ArgumentException:
DoSomethingWithGreek("Theta");
The implicit conversion between a string and EnumValue<TEnum> make this possible.
If you need to allow for case-insensitive comparison then simply use EnumValueCaseIgnored<TEnum> instead.
The performance is outstanding as it uses the length of the names to build a tree in order to parse values and uses an expression tree instead of calling .ToString() on the value.
And more ...
string.Supplant(...)
An alternative to String.Format that takes an array of values.
string.ReplaceWhiteSpace(...)
A shortcut for replacing whitespace with a Regex.
string.ToMetricString(...)
Returns an abbreviated metric representation of a number.
ToByteString(...)
Returns an abbreviated metric representation of a quantity of bytes.
ToPercentString(...)
Shortcut for formating to a percent.
ToNullIfWhiteSpace()
Allows for simple null operators if a string is empty or whitespace.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Primitives (>= 7.0.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Primitives (>= 7.0.0)
-
net10.0
- Microsoft.Extensions.Primitives (>= 10.0.2)
-
net6.0
- Microsoft.Extensions.Primitives (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.Primitives (>= 7.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Open.Text:
| Package | Downloads |
|---|---|
|
Open.Collections
Useful set of collections, and extensions for collections with thread-safe read-write access options. Part of the "Open" set of libraries. |
|
|
Open.DateTime.Extensions
Simple set of DateTime extensions extensions. Code savers like: .Delta(time?) |
|
|
Open.Text.ZLinq
Zero-allocation extensions for Open.Text using ZLinq. Provides SplitAsSegmentsNoAlloc and other high-performance string operations that avoid heap allocations via ZLinq's ValueEnumerable. Part of the "Open" set of libraries. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.2 | 317 | 2/1/2026 |
| 10.0.1 | 115 | 1/31/2026 |
| 10.0.0 | 82 | 1/31/2026 |
| 9.0.1 | 6,790 | 11/13/2025 |
| 9.0.0 | 35,225 | 11/16/2024 |
| 8.2.1 | 319 | 11/16/2024 |
| 8.2.0 | 239 | 11/16/2024 |
| 8.1.0 | 3,073 | 8/28/2024 |
| 8.0.0 | 4,635 | 7/28/2024 |
| 7.0.3 | 5,591 | 7/12/2024 |
| 7.0.2 | 233 | 7/12/2024 |
| 7.0.1 | 518 | 6/26/2024 |
| 7.0.0 | 2,571 | 2/24/2024 |
| 7.0.0-beta | 184 | 2/24/2024 |
| 6.7.0 | 2,554 | 11/8/2023 |
| 6.6.4 | 3,476 | 6/12/2023 |
| 6.6.3 | 319 | 6/2/2023 |
| 6.6.2 | 3,901 | 5/5/2023 |
| 6.6.1 | 334 | 5/4/2023 |
| 6.6.0 | 358 | 4/29/2023 |
| 6.5.4 | 343 | 4/29/2023 |
| 6.5.2 | 706 | 3/31/2023 |
| 6.5.1 | 387 | 3/31/2023 |
| 6.5.0 | 368 | 3/31/2023 |
| 6.4.1 | 3,661 | 3/23/2023 |
| 6.4.0 | 414 | 3/13/2023 |
| 6.3.0 | 1,503 | 10/7/2022 |
| 6.2.1 | 66,282 | 5/20/2022 |
| 6.2.0 | 4,183 | 3/30/2022 |
| 6.1.0 | 645 | 2/25/2022 |
| 6.0.2 | 2,595 | 2/23/2022 |
| 6.0.1 | 619 | 2/22/2022 |
| 6.0.0 | 642 | 2/16/2022 |
| 4.2.6 | 645 | 2/16/2022 |
| 4.2.5 | 626 | 2/16/2022 |
| 4.2.4 | 622 | 2/16/2022 |
| 4.2.3 | 643 | 2/12/2022 |
| 4.2.2 | 575 | 10/28/2021 |
| 4.2.1 | 487 | 10/28/2021 |
| 4.2.0 | 520 | 10/28/2021 |
| 4.1.1 | 565 | 10/25/2021 |
| 4.1.0 | 525 | 10/19/2021 |
| 4.0.1 | 509 | 10/18/2021 |
| 3.6.3 | 664 | 10/17/2021 |
| 3.5.0 | 536 | 10/15/2021 |
| 3.4.3 | 575 | 10/11/2021 |
| 3.4.2 | 768 | 9/20/2021 |
| 2.1.0 | 1,191 | 7/3/2019 |
| 2.0.5 | 1,144 | 6/30/2019 |
| 2.0.4 | 1,178 | 3/31/2019 |
| 1.1.0 | 12,539 | 1/4/2018 |