Meziantou.Framework.ValueStringBuilder 3.0.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Meziantou.Framework.ValueStringBuilder --version 3.0.1
                    
NuGet\Install-Package Meziantou.Framework.ValueStringBuilder -Version 3.0.1
                    
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="Meziantou.Framework.ValueStringBuilder" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.ValueStringBuilder" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.ValueStringBuilder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Meziantou.Framework.ValueStringBuilder --version 3.0.1
                    
#r "nuget: Meziantou.Framework.ValueStringBuilder, 3.0.1"
                    
#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.
#:package Meziantou.Framework.ValueStringBuilder@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Meziantou.Framework.ValueStringBuilder&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.ValueStringBuilder&version=3.0.1
                    
Install as a Cake Tool

Meziantou.Framework.ValueStringBuilder

Meziantou.Framework.ValueStringBuilder provides a high-performance ValueStringBuilder as a ref struct, inspired by the .NET runtime implementation.

Span<char> initialBuffer = stackalloc char[64];
using var sb = new ValueStringBuilder(initialBuffer);

sb.Append("Hello");
sb.Append(' ');
sb.Append("World");

string text = sb.ToString();

Disposing the builder

The builder rents its buffer from ArrayPool<char>.Shared as soon as it outgrows the initial span, so it must be disposed to return that buffer. Declaring it with using is the simplest way to guarantee it.

ToString() is destructive: it returns the content and disposes the builder. After calling it, the builder is reset to its default state, so a second call returns an empty string and appending starts a new buffer.

using var sb = new ValueStringBuilder(stackalloc char[64]);
sb.Append("Hello");

_ = sb.ToString(); // "Hello", and the builder is now disposed
_ = sb.ToString(); // ""

Use AsSpan() when you need to read the content without disposing the builder:

using var sb = new ValueStringBuilder(stackalloc char[64]);
sb.Append("Hello");

ReadOnlySpan<char> content = sb.AsSpan(); // "Hello", the builder is still usable
sb.Append(" World");

Disposing twice is safe, so combining using with a final ToString() is fine.

Reading past the content

RawChars exposes the whole buffer, not just the part that has been written. Everything beyond Length is uninitialized pooled memory and may contain data left by a previous user of the array.

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Meziantou.Framework.ValueStringBuilder:

Package Downloads
Meziantou.Framework.CodeOwners

CODEOWNERS file parser

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.3 5,360 9/13/2026
3.0.2 1,622 9/6/2026
3.0.1 253 9/3/2026
3.0.0 8,409 7/5/2026
2.0.2 2,689 6/13/2026
2.0.1 1,027 5/23/2026
2.0.0 1,571 5/6/2026
1.0.0 144 4/6/2026