ValueStringBuilder: A fast and low allocation StringBuilder for .NET
ValueStringBuilder
is a performant, low-allocation alternative to .NET's StringBuilder
. This documentation will show you how to use the ValueStringBuilder
as well as its limitations. If you have questions or feature requests just head over to the GitHub repository and file an issue.
The library makes heavy use of Span<T>
, stackalloc
and ArrayPool<T>
to achieve low allocations and fast performance.
Download
The package is hosted on nuget.org, so simply reference the package:
PM> Install-Package LinkDotNet.StringBuilder
Example usage
ValueStringBuilder
mostly mimics .NET's StringBuilder
meaning it's similar to use. The main difference is, that ValueStringBuilder
does not support the fluent notation of its big brother.
using var stringBuilder = new ValueStringBuilder(); // Don't forget the 'using' keyword!
stringBuilder.AppendLine("Hello World");
stringBuilder.Append("2+2=");
stringBuilder.Append(4);
Console.WriteLine(stringBuilder.ToString());
This will print:
Hello World
2+2=4
There are also convenient static methods:
Console.WriteLine(ValueStringBuilder.Concat("Hello", " ", "World")); // "Hello World"
Console.WriteLine(ValueStringBuilder.Concat("Hello", 1, 2, 3, "!")); // "Hello123!"