Table of Contents

Class StringBuilderExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides extension methods for the StringBuilder class.

public static class StringBuilderExtensions
Inheritance
StringBuilderExtensions
Inherited Members

Methods

Append(StringBuilder, string, int)

Appends a string to the StringBuilder instance, from its start index up until its end.

public static StringBuilder Append(this StringBuilder stringBuilder, string value, int startIndex)

Parameters

stringBuilder StringBuilder

The StringBuilder instance on which to append the string.

value string

The string to append to the StringBuilder from the specified index onwards.

startIndex int

The index of the first character to append to the StringBuilder.

Returns

StringBuilder

The StringBuilder instance that the string was appended to.

Append(StringBuilder, string, int, int)

Appends a string to the StringBuilder instance, from its start index up until its end.

public static StringBuilder Append(this StringBuilder stringBuilder, string value, int startIndex, int length)

Parameters

stringBuilder StringBuilder

The StringBuilder instance on which to append the string.

value string

The string to append to the StringBuilder from the specified index onwards.

startIndex int

The index of the first character to append to the StringBuilder.

length int

The number of characters to include from the appended string.

Returns

StringBuilder

The StringBuilder instance that the string was appended to.

AppendLine(StringBuilder, char)

public static StringBuilder AppendLine(this StringBuilder stringBuilder, char value)

Parameters

stringBuilder StringBuilder
value char

Returns

StringBuilder

AppendLine(StringBuilder, char*, int)

Appends a sequence of characters, and appends a new line after that.

public static StringBuilder AppendLine(this StringBuilder builder, char* chars, int charCount)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

chars char*

The sequence of characters to append.

charCount int

The number of characters to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLine(StringBuilder, char[])

Appends an array of characters, and appends a new line after that.

public static StringBuilder AppendLine(this StringBuilder builder, char[] chars)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

chars char[]

The array of characters to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLine(StringBuilder, object)

Appends an object's string representation, and appends a new line after that.

public static StringBuilder AppendLine(this StringBuilder builder, object o)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

o object

The object whose string representation to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLine(StringBuilder, ReadOnlyMemory<char>)

Appends a sequence of characters, and appends a new line after that.

public static StringBuilder AppendLine(this StringBuilder builder, ReadOnlyMemory<char> chars)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

chars ReadOnlyMemory<char>

The sequence of characters to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLine(StringBuilder, ReadOnlySpan<char>)

Appends a sequence of characters, and appends a new line after that.

public static StringBuilder AppendLine(this StringBuilder builder, ReadOnlySpan<char> chars)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

chars ReadOnlySpan<char>

The sequence of characters to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLineCount(StringBuilder, int)

Appends a line to the string builder a number of times.

public static StringBuilder AppendLineCount(this StringBuilder stringBuilder, int count)

Parameters

stringBuilder StringBuilder

The StringBuilder instance on which to append.

count int

The number of lines to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLine<T>(StringBuilder, T)

public static StringBuilder AppendLine<T>(this StringBuilder stringBuilder, T value)

Parameters

stringBuilder StringBuilder
value T

Returns

StringBuilder

Type Parameters

T

AppendLines(StringBuilder, IEnumerable<object>)

Appends the string representations of objects in a collection, and appends a new line after that.

public static StringBuilder AppendLines(this StringBuilder builder, IEnumerable<object> objects)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

objects IEnumerable<object>

The objects whose string representations to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLines(StringBuilder, IEnumerable)

Appends the string representations of objects in a collection, and appends a new line after that.

public static StringBuilder AppendLines(this StringBuilder builder, IEnumerable objects)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

objects IEnumerable

The objects whose string representations to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLines(StringBuilder, params object[])

Appends the string representations of objects in a collection, and appends a new line after that.

public static StringBuilder AppendLines(this StringBuilder builder, params object[] objects)

Parameters

builder StringBuilder

The StringBuilder instance on which to append.

objects object[]

The objects whose string representations to append.

Returns

StringBuilder

The same StringBuilder instance.

AppendLower(StringBuilder, string)

Appends the given string's characters by converting them in lowercase.

public static StringBuilder AppendLower(this StringBuilder stringBuilder, string value)

Parameters

stringBuilder StringBuilder

The StringBuilder instance on which to append.

value string

The string to convert to lowercase.

Returns

StringBuilder

The same StringBuilder instance.

AppendUpper(StringBuilder, string)

Appends the given string's characters by converting them in uppercase.

public static StringBuilder AppendUpper(this StringBuilder stringBuilder, string value)

Parameters

stringBuilder StringBuilder

The StringBuilder instance on which to append.

value string

The string to convert to uppercase.

Returns

StringBuilder

The same StringBuilder instance.

Copy(StringBuilder)

Copies this StringBuilder into a new instance.

public static StringBuilder Copy(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder to copy.

Returns

StringBuilder

The new copied StringBuilder instance.

Remarks

In .NET Core 3.1 onwards, this uses the GetChunks method that enumerates the chunks contained in the builder, whereas for the earlier versions of the framework the builder is converted into the full string, and the new instance is initialized through that.

EndsWith(StringBuilder, char)

Determines whether the string ends with the specified character.

public static bool EndsWith(this StringBuilder s, char lastCharacter)

Parameters

s StringBuilder

The StringBuilder to check whether it ends with the specified character.

lastCharacter char

The character to check if it is the last character of the string.

Returns

bool

EndsWith(StringBuilder, string)

Determines whether the string ends with the specified substring.

public static bool EndsWith(this StringBuilder s, string lastCharacters)

Parameters

s StringBuilder

The StringBuilder to check whether it ends with the specified substring.

lastCharacters string

The characters to check if they are the last characters of the string.

Returns

bool

Last(StringBuilder)

Retrieves the last character of the string.

public static char Last(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder whose last character to retrieve.

Returns

char

LastOrNull(StringBuilder)

Retrieves the last character of the string if the string has any characters, otherwise returns null if the StringBuilder is null or if it has no characters.

public static char? LastOrNull(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder whose last character to retrieve.

Returns

char?

Remove(StringBuilder, int)

Removes a range of characters from the specified starting index to the end of the string.

public static StringBuilder Remove(this StringBuilder s, int startingIndex)

Parameters

s StringBuilder

The StringBuilder whose range of characters to remove.

startingIndex int

The starting index from which to remove all characters.

Returns

StringBuilder

RemoveLast(StringBuilder)

Removes the last character of the string.

public static StringBuilder RemoveLast(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder whose last character to remove.

Returns

StringBuilder

RemoveLast(StringBuilder, int)

Removes a number of characters from the end of the string.

public static StringBuilder RemoveLast(this StringBuilder s, int characterCount)

Parameters

s StringBuilder

The StringBuilder whose last characters to remove.

characterCount int

The count of characters to remove from the end of the string.

Returns

StringBuilder

RemoveLastIfEndsWith(StringBuilder, char)

Removes the last character of the string if it ends with the requested character, otherwise none.

public static StringBuilder RemoveLastIfEndsWith(this StringBuilder s, char lastCharacter)

Parameters

s StringBuilder

The StringBuilder whose last character to remove, if the condition is met.

lastCharacter char

The character that should be the last character of the string to remove the last character.

Returns

StringBuilder

RemoveLastIfEndsWith(StringBuilder, string)

Removes the last character of the string if it ends with the requested character, otherwise none.

public static StringBuilder RemoveLastIfEndsWith(this StringBuilder s, string lastCharacters)

Parameters

s StringBuilder

The StringBuilder whose last character to remove, if the condition is met.

lastCharacters string

The characters that should be the last characters of the string to remove them.

Returns

StringBuilder

RemoveLastOrNone(StringBuilder)

Removes the last character of the string if it has any characters, otherwise none.

public static StringBuilder RemoveLastOrNone(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder whose last character to remove, if any.

Returns

StringBuilder

Replace(StringBuilder, string, int, int)

Replaces a part of the string with a new one.

public static StringBuilder Replace(this StringBuilder builder, string replacedString, int startIndex, int length)

Parameters

builder StringBuilder

The original StringBuilder.

replacedString string

The new string to replace to the part of the original one.

startIndex int

The starting index of the substring to replace.

length int

The length of the substring to replace.

Returns

StringBuilder

Substring(StringBuilder, int, int)

Returns a substring of this string with the specified number of characters from a starting index.

public static string Substring(this StringBuilder s, int startingIndex, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

startingIndex int

The index of the original string that the new substring will start from.

length int

The number of characters of the substring.

Returns

string

SubstringBuilder(StringBuilder, int, int)

Returns a substring of this string with the specified number of characters from a starting index as a StringBuilder.

public static StringBuilder SubstringBuilder(this StringBuilder s, int startingIndex, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

startingIndex int

The index of the original string that the new substring will start from.

length int

The number of characters of the substring.

Returns

StringBuilder

SubstringLast(StringBuilder, int)

Returns a substring of this string with the specified number of characters from its end.

public static string SubstringLast(this StringBuilder s, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

length int

The number of characters of the substring.

Returns

string

SubstringLastBuilder(StringBuilder, int)

Returns a substring of this string with the specified number of characters from its end as a StringBuilder.

public static StringBuilder SubstringLastBuilder(this StringBuilder s, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

length int

The number of characters of the substring.

Returns

StringBuilder

SubstringStart(StringBuilder, int)

Returns a substring of this string with the specified number of characters from its start.

public static string SubstringStart(this StringBuilder s, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

length int

The number of characters of the substring.

Returns

string

SubstringStartBuilder(StringBuilder, int)

Returns a substring of this string with the specified number of characters from its start as a StringBuilder.

public static StringBuilder SubstringStartBuilder(this StringBuilder s, int length)

Parameters

s StringBuilder

The StringBuilder to get the substring of.

length int

The number of characters of the substring.

Returns

StringBuilder

TrimEnd(StringBuilder)

Removes the all leading whitespace characters from the current StringBuilder.

public static StringBuilder TrimEnd(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder from which to remove all leading whitespace characters.

Returns

StringBuilder

The original StringBuilder instance.

TrimStart(StringBuilder)

Removes the all leading whitespace characters from the current StringBuilder.

public static StringBuilder TrimStart(this StringBuilder s)

Parameters

s StringBuilder

The StringBuilder from which to remove all leading whitespace characters.

Returns

StringBuilder

The original StringBuilder instance.