StringBuilderExtensions
Extension methods for StringBuilder.
internal static class StringBuilderExtensionsExamples
Section titled “Examples”The following example shows how to use Append and AppendLine with spans.
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(); }}Methods
Section titled “Methods”Append(StringBuilder, ReadOnlySpan<char>)
Section titled “Append(StringBuilder, ReadOnlySpan<char>)”Appends the string representation of a specified read-only character span to this instance.
public static StringBuilder Append(this StringBuilder builder, ReadOnlySpan<char> value);builder
Section titled “builder”The StringBuilder instance to append to.
The read-only character span to append.
Remarks
Section titled “Remarks”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.
Returns
Section titled “Returns”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
public static StringBuilder AppendLine(this StringBuilder builder, ReadOnlySpan<char> value);builder
Section titled “builder”The StringBuilder instance to append to.
The read-only character span to append.
Remarks
Section titled “Remarks”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.
Returns
Section titled “Returns”A reference to this instance after the append operation is completed.