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
stringBuilderStringBuilderThe StringBuilder instance on which to append the string.
valuestringThe string to append to the StringBuilder from the specified index onwards.
startIndexintThe 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
stringBuilderStringBuilderThe StringBuilder instance on which to append the string.
valuestringThe string to append to the StringBuilder from the specified index onwards.
startIndexintThe index of the first character to append to the StringBuilder.
lengthintThe 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
stringBuilderStringBuildervaluechar
Returns
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
builderStringBuilderThe StringBuilder instance on which to append.
charschar*The sequence of characters to append.
charCountintThe 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
builderStringBuilderThe StringBuilder instance on which to append.
charschar[]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
builderStringBuilderThe StringBuilder instance on which to append.
oobjectThe 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
builderStringBuilderThe StringBuilder instance on which to append.
charsReadOnlyMemory<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
builderStringBuilderThe StringBuilder instance on which to append.
charsReadOnlySpan<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
stringBuilderStringBuilderThe StringBuilder instance on which to append.
countintThe 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
stringBuilderStringBuildervalueT
Returns
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
builderStringBuilderThe StringBuilder instance on which to append.
objectsIEnumerable<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
builderStringBuilderThe StringBuilder instance on which to append.
objectsIEnumerableThe 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
builderStringBuilderThe StringBuilder instance on which to append.
objectsobject[]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
stringBuilderStringBuilderThe StringBuilder instance on which to append.
valuestringThe 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
stringBuilderStringBuilderThe StringBuilder instance on which to append.
valuestringThe 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
sStringBuilderThe 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
sStringBuilderThe StringBuilder to check whether it ends with the specified character.
lastCharactercharThe character to check if it is the last character of the string.
Returns
EndsWith(StringBuilder, string)
Determines whether the string ends with the specified substring.
public static bool EndsWith(this StringBuilder s, string lastCharacters)
Parameters
sStringBuilderThe StringBuilder to check whether it ends with the specified substring.
lastCharactersstringThe characters to check if they are the last characters of the string.
Returns
Last(StringBuilder)
Retrieves the last character of the string.
public static char Last(this StringBuilder s)
Parameters
sStringBuilderThe StringBuilder whose last character to retrieve.
Returns
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
sStringBuilderThe 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
sStringBuilderThe StringBuilder whose range of characters to remove.
startingIndexintThe starting index from which to remove all characters.
Returns
RemoveLast(StringBuilder)
Removes the last character of the string.
public static StringBuilder RemoveLast(this StringBuilder s)
Parameters
sStringBuilderThe StringBuilder whose last character to remove.
Returns
RemoveLast(StringBuilder, int)
Removes a number of characters from the end of the string.
public static StringBuilder RemoveLast(this StringBuilder s, int characterCount)
Parameters
sStringBuilderThe StringBuilder whose last characters to remove.
characterCountintThe count of characters to remove from the end of the string.
Returns
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
sStringBuilderThe StringBuilder whose last character to remove, if the condition is met.
lastCharactercharThe character that should be the last character of the string to remove the last character.
Returns
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
sStringBuilderThe StringBuilder whose last character to remove, if the condition is met.
lastCharactersstringThe characters that should be the last characters of the string to remove them.
Returns
RemoveLastOrNone(StringBuilder)
Removes the last character of the string if it has any characters, otherwise none.
public static StringBuilder RemoveLastOrNone(this StringBuilder s)
Parameters
sStringBuilderThe StringBuilder whose last character to remove, if any.
Returns
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
builderStringBuilderThe original StringBuilder.
replacedStringstringThe new string to replace to the part of the original one.
startIndexintThe starting index of the substring to replace.
lengthintThe length of the substring to replace.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
startingIndexintThe index of the original string that the new substring will start from.
lengthintThe number of characters of the substring.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
startingIndexintThe index of the original string that the new substring will start from.
lengthintThe number of characters of the substring.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
lengthintThe number of characters of the substring.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
lengthintThe number of characters of the substring.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
lengthintThe number of characters of the substring.
Returns
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
sStringBuilderThe StringBuilder to get the substring of.
lengthintThe number of characters of the substring.
Returns
TrimEnd(StringBuilder)
Removes the all leading whitespace characters from the current StringBuilder.
public static StringBuilder TrimEnd(this StringBuilder s)
Parameters
sStringBuilderThe 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
sStringBuilderThe StringBuilder from which to remove all leading whitespace characters.
Returns
- StringBuilder
The original StringBuilder instance.