StringBuilderExtensions Class

Provides extension methods for StringBuilder.

public static class StringBuilderExtensions

Methods

NameDescription
StringBuilder.AppendClippedLiteral(StringLiteralKind, ReadOnlySpan<char>, int, int)Appends the specified span of characters, expressed as a C# string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedLiteral(StringLiteralKind, ReadOnlySpan<char>, int, int, bool)Appends the specified span of characters, expressed as a C# string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendClippedLiteral(StringLiteralKind, string?, int, int)Appends the specified string, expressed as a C# string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedLiteral(StringLiteralKind, string?, int, int, bool)Appends the specified string, expressed as a C# string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendClippedQuotedLiteral(ReadOnlySpan<char>, int, int)Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedQuotedLiteral(ReadOnlySpan<char>, int, int, bool)Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendClippedQuotedLiteral(string?, int, int)Appends the specified string, expressed as a C# quoted string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedQuotedLiteral(string?, int, int, bool)Appends the specified string, expressed as a C# quoted string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendClippedVerbatimLiteral(ReadOnlySpan<char>, int, int)Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedVerbatimLiteral(ReadOnlySpan<char>, int, int, bool)Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendClippedVerbatimLiteral(string?, int, int)Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.
StringBuilder.AppendClippedVerbatimLiteral(string?, int, int, bool)Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
StringBuilder.AppendLiteral(StringLiteralKind, ReadOnlySpan<char>)Appends the specified span of characters, expressed as a C# string literal, to the end of this instance.
StringBuilder.AppendLiteral(StringLiteralKind, string?)Appends the specified string, expressed as a C# string literal, to the end of this instance.
StringBuilder.AppendQuotedLiteral(ReadOnlySpan<char>)Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance.
StringBuilder.AppendQuotedLiteral(string?)Appends the specified string, expressed as a C# quoted string literal, to the end of this instance.
StringBuilder.AppendResult(ReadOnlySpanFunc<char>)Appends the result of a method to the end of this builder.
StringBuilder.AppendResult(Func<string?>)Appends the result of a method to the end of this builder.
StringBuilder.AppendVerbatimLiteral(ReadOnlySpan<char>)Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance.
StringBuilder.AppendVerbatimLiteral(string?)Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance.

StringBuilder.AppendClippedLiteral overloads

StringBuilder.AppendClippedLiteral(StringLiteralKind, ReadOnlySpan<char>, int, int)

Appends the specified span of characters, expressed as a C# string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedLiteral(StringLiteralKind literalKind, ReadOnlySpan<char> chars, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedLiteral(StringLiteralKind, ReadOnlySpan<char>, int, int, bool)

Appends the specified span of characters, expressed as a C# string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedLiteral(StringLiteralKind literalKind, ReadOnlySpan<char> chars, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedLiteral(StringLiteralKind, string?, int, int)

Appends the specified string, expressed as a C# string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedLiteral(StringLiteralKind literalKind, string? str, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendClippedLiteral(StringLiteralKind, string?, int, int, bool)

Appends the specified string, expressed as a C# string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedLiteral(StringLiteralKind literalKind, string? str, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendClippedQuotedLiteral overloads

StringBuilder.AppendClippedQuotedLiteral(ReadOnlySpan<char>, int, int)

Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedQuotedLiteral(ReadOnlySpan<char> chars, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedQuotedLiteral(ReadOnlySpan<char>, int, int, bool)

Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedQuotedLiteral(ReadOnlySpan<char> chars, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedQuotedLiteral(string?, int, int)

Appends the specified string, expressed as a C# quoted string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedQuotedLiteral(string? str, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendClippedQuotedLiteral(string?, int, int, bool)

Appends the specified string, expressed as a C# quoted string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedQuotedLiteral(string? str, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendClippedVerbatimLiteral overloads

StringBuilder.AppendClippedVerbatimLiteral(ReadOnlySpan<char>, int, int)

Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedVerbatimLiteral(ReadOnlySpan<char> chars, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedVerbatimLiteral(ReadOnlySpan<char>, int, int, bool)

Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance. If the span is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedVerbatimLiteral(ReadOnlySpan<char> chars, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.

StringBuilder.AppendClippedVerbatimLiteral(string?, int, int)

Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (three dots ...), then it is clipped, taking only the first headLength characters, followed by the ellipsis and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedVerbatimLiteral(string? str, int headLength, int tailLength)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendClippedVerbatimLiteral(string?, int, int, bool)

Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.

extension(StringBuilder @this)
{
    public StringBuilder AppendClippedVerbatimLiteral(string? str, int headLength, int tailLength, bool useUnicodeEllipsis)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
headLength int
The number of characters to leave before clipping.
tailLength int
The number of characters to leave after clipping.
useUnicodeEllipsis bool
true to use a single Unicode character Ellipsis ('\x2026', …) to replace the clipped part; false to use three dots (...) instead.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentOutOfRangeException
headLength is less than 0. - or - tailLength is less than 0.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

StringBuilder.AppendLiteral overloads

StringBuilder.AppendLiteral(StringLiteralKind, ReadOnlySpan<char>)

Appends the specified span of characters, expressed as a C# string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendLiteral(StringLiteralKind literalKind, ReadOnlySpan<char> chars)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
chars ReadOnlySpan<char>
The characters to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
See also

StringBuilder.AppendLiteral(StringLiteralKind, string?)

Appends the specified string, expressed as a C# string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendLiteral(StringLiteralKind literalKind, string? str)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
literalKind StringLiteralKind
A StringLiteralKind constant specifying the kind of string literal to append.
str string?
The string to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
ArgumentException
literalKind is neither StringLiteralKind.Quoted nor StringLiteralKind.Verbatim.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

See also

StringBuilder.AppendQuotedLiteral overloads

StringBuilder.AppendQuotedLiteral(ReadOnlySpan<char>)

Appends the specified span of characters, expressed as a C# quoted string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendQuotedLiteral(ReadOnlySpan<char> chars)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
See also

StringBuilder.AppendQuotedLiteral(string?)

Appends the specified string, expressed as a C# quoted string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendQuotedLiteral(string? str)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

See also

StringBuilder.AppendResult overloads

StringBuilder.AppendResult(ReadOnlySpanFunc<char>)

Appends the result of a method to the end of this builder.

extension(StringBuilder @this)
{
    public StringBuilder AppendResult(ReadOnlySpanFunc<char> func)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
func ReadOnlySpanFunc<char>
The method to call.
Returns

StringBuilder A reference to this after the operation is completed.

Exceptions
ArgumentNullException
this is null. - or - func is null.

StringBuilder.AppendResult(Func<string?>)

Appends the result of a method to the end of this builder.

extension(StringBuilder @this)
{
    public StringBuilder AppendResult(Func<string?> provider)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
provider Func<string?>
The method to call.
Returns

StringBuilder A reference to this after the operation is completed.

Exceptions
ArgumentNullException
this is null. - or - provider is null.

StringBuilder.AppendVerbatimLiteral overloads

StringBuilder.AppendVerbatimLiteral(ReadOnlySpan<char>)

Appends the specified span of characters, expressed as a C# verbatim string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendVerbatimLiteral(ReadOnlySpan<char> chars)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
chars ReadOnlySpan<char>
The characters to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
See also

StringBuilder.AppendVerbatimLiteral(string?)

Appends the specified string, expressed as a C# verbatim string literal, to the end of this instance.

extension(StringBuilder @this)
{
    public StringBuilder AppendVerbatimLiteral(string? str)
}
Parameters
this StringBuilder
The StringBuilder on which this method is called.
str string?
The string to append.
Returns

StringBuilder A reference to this instance after the append operation has completed.

Exceptions
ArgumentNullException
this is null.
Remarks

If str is null, the string null (without surrounding quotes) will be appended to this.

See also