Skip to content

StringBuilderExtensions

Extension methods for StringBuilder.

C# Signature
internal static class StringBuilderExtensions

The following example shows how to use Append and AppendLine with spans.

C#
using System;
using System.Text;
using Hertzole.SourceGen;
public static class Joiner
{
public static string Join(ReadOnlySpan<char> a, ReadOnlySpan<char> b)
{
StringBuilder builder = new StringBuilder();
builder.Append(a);
builder.Append(", ");
builder.AppendLine(b);
return builder.ToString();
}
}

Appends the string representation of a specified read-only character span to this instance.

C# Signature
public static StringBuilder Append(this StringBuilder builder, ReadOnlySpan<char> value);

The StringBuilder instance to append to.

The read-only character span to append.

If the project allows unsafe code, this method uses a pointer to the span instead of appending each character in the span, thus being faster. It is recommended to enable unsafe code.

A reference to this instance after the append operation is completed.

AppendLine(StringBuilder, ReadOnlySpan<char>)

Section titled “AppendLine(StringBuilder, ReadOnlySpan<char>)”

Appends the string representation of a specified read-only character span followed by the default line terminator to the end of the current StringBuilder object

C# Signature
public static StringBuilder AppendLine(this StringBuilder builder, ReadOnlySpan<char> value);

The StringBuilder instance to append to.

The read-only character span to append.

If the project allows unsafe code, this method uses a pointer to the span instead of appending each character in the span, thus being faster. It is recommended to enable unsafe code.

A reference to this instance after the append operation is completed.