Struct ValueStringBuilder
- Namespace
- LinkDotNet.StringBuilder
- Assembly
- LinkDotNet.StringBuilder.dll
A string builder which minimizes as many heap allocations as possible.
public ref struct ValueStringBuilder : IDisposable
- Implements
- Inherited Members
- Extension Methods
Remarks
This is a ref struct which has certain limitations. You can only store it in a local variable or another ref struct.
You should dispose it after use to ensure the rented buffer is returned to the array pool.
Constructors
ValueStringBuilder()
Initializes a new instance of the ValueStringBuilder struct using a rented buffer of capacity 32.
public ValueStringBuilder()
ValueStringBuilder(int)
Initializes a new instance of the ValueStringBuilder struct.
public ValueStringBuilder(int initialCapacity)
Parameters
initialCapacityintThe initial capacity that will be allocated for this instance.
ValueStringBuilder(scoped ReadOnlySpan<char>)
Initializes a new instance of the ValueStringBuilder struct.
public ValueStringBuilder(scoped ReadOnlySpan<char> initialText)
Parameters
initialTextReadOnlySpan<char>The initial text used to initialize this instance.
ValueStringBuilder(Span<char>)
Initializes a new instance of the ValueStringBuilder struct.
public ValueStringBuilder(Span<char> initialBuffer)
Parameters
Properties
Capacity
Gets the current maximum capacity before the span must be resized.
public readonly int Capacity { get; }
Property Value
- int
The current maximum capacity before the span must be resized.
IsEmpty
Gets a value indicating whether the builder's length is 0.
public readonly bool IsEmpty { get; }
Property Value
this[int]
Returns the character at the given index or throws an IndexOutOfRangeException if the index is bigger than the string.
public readonly ref char this[int index] { get; }
Parameters
indexintCharacter position to be retrieved.
Property Value
Length
Gets the current length of the represented string.
public readonly int Length { get; }
Property Value
- int
The current length of the represented string.
Methods
Append(ref AppendInterpolatedStringHandler)
Appends an interpolated string to the builder.
public void Append(ref ValueStringBuilder.AppendInterpolatedStringHandler handler)
Parameters
handlerValueStringBuilder.AppendInterpolatedStringHandlerThe interpolated string handler.
Append(bool)
Appends the string representation of the boolean.
public void Append(bool value)
Parameters
valueboolBool value to add.
Append(char)
Appends a single character.
public void Append(char value)
Parameters
valuecharCharacter to add.
Append(char*, int)
Appends a character buffer.
public void Append(char* value, int length)
Parameters
valuechar*The pointer to the start of the buffer.
lengthintThe number of characters in the buffer.
Append(ReadOnlyMemory<char>)
Appends a slice of memory.
public void Append(ReadOnlyMemory<char> memory)
Parameters
memoryReadOnlyMemory<char>The memory to add.
Append(scoped ReadOnlySpan<char>)
Appends a string.
public void Append(scoped ReadOnlySpan<char> str)
Parameters
strReadOnlySpan<char>String to be added to this builder.
Append(string?)
Appends a string.
public void Append(string? value)
Parameters
valuestringThe string to be added to this builder.
Append(Rune)
Appends a single rune to the string builder.
public void Append(Rune value)
Parameters
valueRuneRune to add.
AppendFormat<T>(scoped ReadOnlySpan<char>, T)
Appends the format string to the given ValueStringBuilder instance.
public void AppendFormat<T>(scoped ReadOnlySpan<char> format, T arg)
Parameters
formatReadOnlySpan<char>Format string.
argTArgument for
{0}.
Type Parameters
TAny type.
Remarks
The current version does not allow for a custom format.
So:
AppendFormat("{0:00}")
is not allowed and will result in an exception.
AppendFormat<T1, T2>(scoped ReadOnlySpan<char>, T1, T2)
Appends the format string to the given ValueStringBuilder instance.
public void AppendFormat<T1, T2>(scoped ReadOnlySpan<char> format, T1 arg1, T2 arg2)
Parameters
formatReadOnlySpan<char>Format string.
arg1T1Argument for
{0}.arg2T2Argument for
{1}.
Type Parameters
T1Any type for
arg1.T2Any type for
arg2.
Remarks
The current version does not allow for a custom format.
So:
AppendFormat("{0:00}")
is not allowed and will result in an exception.
AppendFormat<T1, T2, T3>(scoped ReadOnlySpan<char>, T1, T2, T3)
Appends the format string to the given ValueStringBuilder instance.
public void AppendFormat<T1, T2, T3>(scoped ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3)
Parameters
formatReadOnlySpan<char>Format string.
arg1T1Argument for
{0}.arg2T2Argument for
{1}.arg3T3Argument for
{2}.
Type Parameters
T1Any type for
arg1.T2Any type for
arg2.T3Any type for
arg3.
Remarks
The current version does not allow for a custom format.
So:
AppendFormat("{0:00}")
is not allowed and will result in an exception.
AppendFormat<T1, T2, T3, T4>(scoped ReadOnlySpan<char>, T1, T2, T3, T4)
Appends the format string to the given ValueStringBuilder instance.
public void AppendFormat<T1, T2, T3, T4>(scoped ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Parameters
formatReadOnlySpan<char>Format string.
arg1T1Argument for
{0}.arg2T2Argument for
{1}.arg3T3Argument for
{2}.arg4T4Argument for
{3}.
Type Parameters
T1Any type for
arg1.T2Any type for
arg2.T3Any type for
arg3.T4Any type for
arg4.
Remarks
The current version does not allow for a custom format.
So:
AppendFormat("{0:00}")
is not allowed and will result in an exception.
AppendFormat<T1, T2, T3, T4, T5>(scoped ReadOnlySpan<char>, T1, T2, T3, T4, T5)
Appends the format string to the given ValueStringBuilder instance.
public void AppendFormat<T1, T2, T3, T4, T5>(scoped ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
Parameters
formatReadOnlySpan<char>Format string.
arg1T1Argument for
{0}.arg2T2Argument for
{1}.arg3T3Argument for
{2}.arg4T4Argument for
{3}.arg5T5Argument for
{4}.
Type Parameters
T1Any type for
arg1.T2Any type for
arg2.T3Any type for
arg3.T4Any type for
arg4.T5Any type for
arg5.
Remarks
The current version does not allow for a custom format.
So:
AppendFormat("{0:00}")
is not allowed and will result in an exception.
AppendJoin(char, IEnumerable<string?>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin(char separator, IEnumerable<string?> values)
Parameters
separatorcharCharacter used as separator between the entries.
valuesIEnumerable<string>Enumerable of strings to be concatenated.
AppendJoin(char, scoped ReadOnlySpan<string?>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin(char separator, scoped ReadOnlySpan<string?> values)
Parameters
separatorcharCharacter used as separator between the entries.
valuesReadOnlySpan<string>Enumerable of strings to be concatenated.
AppendJoin(ReadOnlySpan<char>, IEnumerable<string?>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin(ReadOnlySpan<char> separator, IEnumerable<string?> values)
Parameters
separatorReadOnlySpan<char>String used as separator between the entries.
valuesIEnumerable<string>Enumerable of strings to be concatenated.
AppendJoin(ReadOnlySpan<char>, scoped ReadOnlySpan<string?>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin(ReadOnlySpan<char> separator, scoped ReadOnlySpan<string?> values)
Parameters
separatorReadOnlySpan<char>String used as separator between the entries.
valuesReadOnlySpan<string>Enumerable of strings to be concatenated.
AppendJoin(Rune, IEnumerable<string?>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin(Rune separator, IEnumerable<string?> values)
Parameters
separatorRuneRune used as separator between the entries.
valuesIEnumerable<string>Enumerable of strings to be concatenated.
AppendJoin<T>(char, IEnumerable<T>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin<T>(char separator, IEnumerable<T> values)
Parameters
separatorcharCharacter used as separator between the entries.
valuesIEnumerable<T>Enumerable to be concatenated.
Type Parameters
TType of the given enumerable.
AppendJoin<T>(char, scoped ReadOnlySpan<T>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin<T>(char separator, scoped ReadOnlySpan<T> values)
Parameters
separatorcharCharacter used as separator between the entries.
valuesReadOnlySpan<T>Enumerable to be concatenated.
Type Parameters
TType of the given enumerable.
AppendJoin<T>(scoped ReadOnlySpan<char>, IEnumerable<T>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin<T>(scoped ReadOnlySpan<char> separator, IEnumerable<T> values)
Parameters
separatorReadOnlySpan<char>String used as separator between the entries.
valuesIEnumerable<T>Enumerable to be concatenated.
Type Parameters
TType of the given enumerable.
AppendJoin<T>(scoped ReadOnlySpan<char>, ReadOnlySpan<T>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin<T>(scoped ReadOnlySpan<char> separator, ReadOnlySpan<T> values)
Parameters
separatorReadOnlySpan<char>String used as separator between the entries.
valuesReadOnlySpan<T>Enumerable to be concatenated.
Type Parameters
TType of the given enumerable.
AppendJoin<T>(Rune, IEnumerable<T>)
Concatenates and appends all values with the given separator between each entry at the end of the string.
public void AppendJoin<T>(Rune separator, IEnumerable<T> values)
Parameters
separatorRuneRune used as separator between the entries.
valuesIEnumerable<T>Enumerable to be concatenated.
Type Parameters
TType of the given enumerable.
AppendLine()
Appends NewLine.
public void AppendLine()
AppendLine(ref AppendInterpolatedStringHandler)
Appends an interpolated string followed by a new line to the builder.
public void AppendLine(ref ValueStringBuilder.AppendInterpolatedStringHandler handler)
Parameters
handlerValueStringBuilder.AppendInterpolatedStringHandlerThe interpolated string handler.
AppendLine(scoped ReadOnlySpan<char>)
Calls Append(scoped ReadOnlySpan<char>) and appends NewLine.
public void AppendLine(scoped ReadOnlySpan<char> str)
Parameters
strReadOnlySpan<char>String to be added to this builder.
AppendLine(string?)
Calls Append(string?) and appends NewLine.
public void AppendLine(string? value)
Parameters
valuestringThe string to be added to this builder.
AppendPadLeft(scoped ReadOnlySpan<char>, int, char)
Appends the source string padded on the left with the given character to reach the specified total width.
public void AppendPadLeft(scoped ReadOnlySpan<char> source, int sourceTotalWidth, char paddingChar = ' ')
Parameters
sourceReadOnlySpan<char>The source string to pad and append.
sourceTotalWidthintTotal width of the padded string.
paddingCharcharCharacter to pad the string with. Defaults to space.
AppendPadRight(scoped ReadOnlySpan<char>, int, char)
Appends the source string padded on the right with the given character to reach the specified total width.
public void AppendPadRight(scoped ReadOnlySpan<char> source, int sourceTotalWidth, char paddingChar = ' ')
Parameters
sourceReadOnlySpan<char>The source string to pad and append.
sourceTotalWidthintTotal width of the padded string.
paddingCharcharCharacter to pad the string with. Defaults to space.
AppendSpan(int)
Appends a span of the given length, which can be written to later.
public Span<char> AppendSpan(int length)
Parameters
lengthintInteger representing the number of characters to be appended.
Returns
Append<T>(T, scoped ReadOnlySpan<char>, int, IFormatProvider?)
Appends the string representation of the value.
public void Append<T>(T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null) where T : ISpanFormattable
Parameters
valueTFormattable span to add.
formatReadOnlySpan<char>Optional formatter. If not provided the default of the given instance is taken.
bufferSizeintSize of the buffer allocated. If you have a custom type that implements ISpanFormattable that requires more space than the default (36 characters), adjust the value.
formatProviderIFormatProviderOptional format provider.
Type Parameters
TAny ISpanFormattable.
AsSpan()
Returns the string as an ReadOnlySpan<T>.
public readonly ReadOnlySpan<char> AsSpan()
Returns
- ReadOnlySpan<char>
The filled array as ReadOnlySpan<T>.
AsSpan(int)
Returns the string as an ReadOnlySpan<T>.
public readonly ReadOnlySpan<char> AsSpan(int startIndex)
Parameters
startIndexintThe starting position of the substring in this instance.
Returns
- ReadOnlySpan<char>
The filled array as ReadOnlySpan<T>.
AsSpan(int, int)
Returns the string as an ReadOnlySpan<T>.
public readonly ReadOnlySpan<char> AsSpan(int startIndex, int length)
Parameters
startIndexintThe starting position of the substring in this instance.
lengthintThe length of the substring.
Returns
- ReadOnlySpan<char>
The filled array as ReadOnlySpan<T>.
AsSpan(Range)
Returns the string as an ReadOnlySpan<T>.
public readonly ReadOnlySpan<char> AsSpan(Range range)
Parameters
rangeRangeThe range to be retrieved.
Returns
- ReadOnlySpan<char>
The filled array as ReadOnlySpan<T>.
Clear()
Clears the internal representation of the string.
public void Clear()
Remarks
This will not enforce some re-allocation or shrinking of the internal buffer. The size stays the same.
Concat<T>(params ReadOnlySpan<T>)
Concatenates the string representation of multiple objects together.
public static string Concat<T>(params ReadOnlySpan<T> values)
Parameters
valuesReadOnlySpan<T>Values to be concatenated.
Returns
- string
The concatenated string, or an empty string if
valuesis empty.
Type Parameters
TAny type for
valuesthat can be converted to string.
Concat<T1>(T1)
Creates the string representation of an object.
public static string Concat<T1>(T1 arg1)
Parameters
arg1T1First value to be concatenated.
Returns
- string
The string representation of the object.
Type Parameters
T1Any type for
arg1that can be converted to string.
Concat<T1, T2>(T1, T2)
Concatenates the string representation of two objects together.
public static string Concat<T1, T2>(T1 arg1, T2 arg2)
Parameters
arg1T1First value to be concatenated.
arg2T2Second value to be concatenated.
Returns
- string
The concatenated string.
Type Parameters
T1Any type for
arg1that can be converted to string.T2Any type for
arg2that can be converted to string.
Concat<T1, T2, T3>(T1, T2, T3)
Concatenates the string representation of three objects together.
public static string Concat<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3)
Parameters
arg1T1First value to be concatenated.
arg2T2Second value to be concatenated.
arg3T3Third value to be concatenated.
Returns
- string
The concatenated string.
Type Parameters
T1Any type for
arg1that can be converted to string.T2Any type for
arg2that can be converted to string.T3Any type for
arg3that can be converted to string.
Concat<T1, T2, T3, T4>(T1, T2, T3, T4)
Concatenates the string representation of four objects together.
public static string Concat<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Parameters
arg1T1First value to be concatenated.
arg2T2Second value to be concatenated.
arg3T3Third value to be concatenated.
arg4T4Fourth value to be concatenated.
Returns
- string
The concatenated string.
Type Parameters
T1Any type for
arg1that can be converted to string.T2Any type for
arg2that can be converted to string.T3Any type for
arg3that can be converted to string.T4Any type for
arg4that can be converted to string.
Concat<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5)
Concatenates the string representation of five objects together.
public static string Concat<T1, T2, T3, T4, T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
Parameters
arg1T1First value to be concatenated.
arg2T2Second value to be concatenated.
arg3T3Third value to be concatenated.
arg4T4Fourth value to be concatenated.
arg5T5Fifth value to be concatenated.
Returns
- string
The concatenated string.
Type Parameters
T1Any type for
arg1that can be converted to string.T2Any type for
arg2that can be converted to string.T3Any type for
arg3that can be converted to string.T4Any type for
arg4that can be converted to string.T5Any type for
arg5that can be converted to string.
Contains(scoped ReadOnlySpan<char>, StringComparison)
Returns whether a specified substring occurs within this string.
public readonly bool Contains(scoped ReadOnlySpan<char> word, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
wordReadOnlySpan<char>Word to look for in this string.
comparisonTypeStringComparisonOne of the enumeration values that specifies the rules for the search.
Returns
- bool
True if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false.
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) comparison.
Dispose()
Disposes the instance and returns the rented buffer to the array pool if needed.
public void Dispose()
EnsureCapacity(int)
Ensures the builder's buffer size is at least newCapacity, renting a larger buffer if not.
public void EnsureCapacity(int newCapacity)
Parameters
newCapacityintNew capacity for the builder.
Remarks
If Length is already >= newCapacity, nothing is done.
Equals(scoped ReadOnlySpan<char>)
Returns whether the characters in this builder are equal to the characters in the given span.
public readonly bool Equals(scoped ReadOnlySpan<char> span)
Parameters
spanReadOnlySpan<char>The character span to compare with the current instance.
Returns
Equals(scoped ReadOnlySpan<char>, StringComparison)
Returns whether the characters in this builder are equal to the characters in the given span according to the given comparison type.
public readonly bool Equals(scoped ReadOnlySpan<char> span, StringComparison comparisonType)
Parameters
spanReadOnlySpan<char>The character span to compare with the current instance.
comparisonTypeStringComparisonThe way to compare the sequences of characters.
Returns
GetEnumerator()
Creates an enumerator over the characters in the builder.
public readonly ValueStringBuilder.Enumerator GetEnumerator()
Returns
- ValueStringBuilder.Enumerator
An enumerator over the characters in the builder.
GetPinnableReference()
Gets a pinnable reference to the represented string from this builder. The content after Length is not guaranteed to be null terminated.
public readonly ref char GetPinnableReference()
Returns
- char
The pointer to the first instance of the string represented by this builder.
Remarks
This method is used for use-cases where the user wants to use "fixed" calls like the following:
using var stringBuilder = new ValueStringBuilder();
stringBuilder.Append("Hello World");
fixed (var* buffer = stringBuilder) { ... }
IndexOf(scoped ReadOnlySpan<char>, int, StringComparison)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
public readonly int IndexOf(scoped ReadOnlySpan<char> word, int startIndex, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
wordReadOnlySpan<char>Word to look for in this string.
startIndexintIndex to begin with.
comparisonTypeStringComparisonOne of the enumeration values that specifies the rules for the search.
Returns
- int
The index of the found
wordin this string or -1 if not found.
IndexOf(scoped ReadOnlySpan<char>, StringComparison)
Returns the index within this string of the first occurrence of the specified substring.
public readonly int IndexOf(scoped ReadOnlySpan<char> word, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
wordReadOnlySpan<char>Word to look for in this string.
comparisonTypeStringComparisonOne of the enumeration values that specifies the rules for the search.
Returns
- int
The index of the found
wordin this string or -1 if not found.
Insert(int, bool)
Insert the string representation of the boolean to the builder at the given index.
public void Insert(int index, bool value)
Parameters
Insert(int, char)
Insert the string representation of the character to the builder at the given index.
public void Insert(int index, char value)
Parameters
Insert(int, scoped ReadOnlySpan<char>)
Insert the given span into the builder at the given index.
public void Insert(int index, scoped ReadOnlySpan<char> value)
Parameters
indexintIndex where
valueshould be inserted.valueReadOnlySpan<char>String to insert into this builder.
Insert(int, Rune)
Insert the string representation of the rune to the builder at the given index.
public void Insert(int index, Rune value)
Parameters
Insert<T>(int, T, scoped ReadOnlySpan<char>, int, IFormatProvider?)
Insert the string representation of the value to the builder at the given index.
public void Insert<T>(int index, T value, scoped ReadOnlySpan<char> format = default, int bufferSize = 36, IFormatProvider? formatProvider = null) where T : ISpanFormattable
Parameters
indexintIndex where
valueshould be inserted.valueTFormattable value to insert into this builder.
formatReadOnlySpan<char>Optional formatter. If not provided the default of the given instance is taken.
bufferSizeintSize of the buffer allocated on the stack.
formatProviderIFormatProviderOptional format provider.
Type Parameters
TAny ISpanFormattable.
LastIndexOf(scoped ReadOnlySpan<char>, int, StringComparison)
Returns the index within this string of the last occurrence of the specified substring, starting at the specified index.
public readonly int LastIndexOf(scoped ReadOnlySpan<char> word, int startIndex, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
wordReadOnlySpan<char>Word to look for in this string.
startIndexintIndex to begin with.
comparisonTypeStringComparisonOne of the enumeration values that specifies the rules for the search.
Returns
- int
The index of the found
wordin this string or -1 if not found.
LastIndexOf(scoped ReadOnlySpan<char>, StringComparison)
Returns the index within this string of the last occurrence of the specified substring.
public readonly int LastIndexOf(scoped ReadOnlySpan<char> word, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
wordReadOnlySpan<char>Word to look for in this string.
comparisonTypeStringComparisonOne of the enumeration values that specifies the rules for the search.
Returns
- int
The index of the found
wordin this string or -1 if not found.
PadLeft(int, char)
Pads the left side of the string with the given character.
public void PadLeft(int totalWidth, char paddingChar)
Parameters
totalWidthintTotal width of the string after padding.
paddingCharcharCharacter to pad the string with.
PadRight(int, char)
Pads the right side of the string with the given character.
public void PadRight(int totalWidth, char paddingChar)
Parameters
totalWidthintTotal width of the string after padding.
paddingCharcharCharacter to pad the string with.
Remove(int, int)
Removes a range of characters from this builder.
public void Remove(int startIndex, int length)
Parameters
startIndexintThe inclusive index from where the string gets removed.
lengthintThe length of the slice to remove.
Remarks
This method will not affect the internal size of the string.
Replace(char, char)
Replaces all instances of one character with another in this builder.
public readonly void Replace(char oldValue, char newValue)
Parameters
Replace(char, char, int, int)
Replaces all instances of one character with another in this builder.
public readonly void Replace(char oldValue, char newValue, int startIndex, int count)
Parameters
oldValuecharThe character to replace.
newValuecharThe character to replace
oldValuewith.startIndexintThe index to start in this builder.
countintThe number of characters to read in this builder.
Replace(scoped ReadOnlySpan<char>, scoped ReadOnlySpan<char>)
Replaces all instances of one string with another in this builder.
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue)
Parameters
oldValueReadOnlySpan<char>The string to replace.
newValueReadOnlySpan<char>The string to replace
oldValuewith.
Remarks
If newValue is empty, instances of oldValue are removed.
Replace(scoped ReadOnlySpan<char>, scoped ReadOnlySpan<char>, int, int)
Replaces all instances of one string with another in this builder.
public void Replace(scoped ReadOnlySpan<char> oldValue, scoped ReadOnlySpan<char> newValue, int startIndex, int count)
Parameters
oldValueReadOnlySpan<char>The string to replace.
newValueReadOnlySpan<char>The string to replace
oldValuewith.startIndexintThe index to start in this builder.
countintThe number of characters to read in this builder.
Remarks
If newValue is empty, instances of oldValue are removed.
Replace(Rune, Rune)
Replaces all instances of one rune with another in this builder.
public void Replace(Rune oldValue, Rune newValue)
Parameters
Replace(Rune, Rune, int, int)
Replaces all instances of one rune with another in this builder.
public void Replace(Rune oldValue, Rune newValue, int startIndex, int count)
Parameters
oldValueRuneThe rune to replace.
newValueRuneThe rune to replace
oldValuewith.startIndexintThe index to start in this builder.
countintThe number of characters to read in this builder.
ReplaceGeneric<T>(scoped ReadOnlySpan<char>, T)
Replaces all instances of one string with another in this builder.
public void ReplaceGeneric<T>(scoped ReadOnlySpan<char> oldValue, T newValue)
Parameters
oldValueReadOnlySpan<char>The string to replace.
newValueTObject to replace
oldValuewith.
Type Parameters
TAny type.
Remarks
If newValue is from type ISpanFormattable an optimized version is taken.
Otherwise the ToString method is called.
ReplaceGeneric<T>(scoped ReadOnlySpan<char>, T, int, int)
Replaces all instances of one string with another in this builder.
public void ReplaceGeneric<T>(scoped ReadOnlySpan<char> oldValue, T newValue, int startIndex, int count)
Parameters
oldValueReadOnlySpan<char>The string to replace.
newValueTObject to replace
oldValuewith.startIndexintThe index to start in this builder.
countintThe number of characters to read in this builder.
Type Parameters
TAny type.
Remarks
If newValue is ISpanFormattable, TryFormat is used.
Otherwise, ToString is used.
Reverse()
Reverses the sequence of elements in this instance.
public readonly void Reverse()
ToString()
Creates a string instance from the builder.
public override readonly string ToString()
Returns
ToString(int)
Creates a string instance from the builder.
public readonly string ToString(int startIndex)
Parameters
startIndexintThe starting position of the substring in this instance.
Returns
ToString(int, int)
Creates a string instance from the builder.
public readonly string ToString(int startIndex, int length)
Parameters
startIndexintThe starting position of the substring in this instance.
lengthintThe length of the substring.
Returns
ToString(Range)
Creates a string instance from the builder in the given range.
public readonly string ToString(Range range)
Parameters
rangeRangeThe range to be retrieved.
Returns
Trim()
Removes all whitespace characters from the start and end of this builder.
public void Trim()
Trim(char)
Removes all occurrences of the specified character from the start and end of this builder.
public void Trim(char value)
Parameters
valuecharThe character to remove.
TrimEnd()
Removes all whitespace characters from the end of this builder.
public void TrimEnd()
TrimEnd(char)
Removes all occurrences of the specified character from the end of this builder.
public void TrimEnd(char value)
Parameters
valuecharThe character to remove.
TrimPrefix(scoped ReadOnlySpan<char>, StringComparison)
Removes the specified sequence of characters from the start of this builder.
public void TrimPrefix(scoped ReadOnlySpan<char> value, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valueReadOnlySpan<char>The sequence of characters to remove.
comparisonTypeStringComparisonThe way to compare the sequences of characters.
TrimStart()
Removes all whitespace characters from the start of this builder.
public void TrimStart()
TrimStart(char)
Removes all occurrences of the specified character from the start of this builder.
public void TrimStart(char value)
Parameters
valuecharThe character to remove.
TrimSuffix(scoped ReadOnlySpan<char>, StringComparison)
Removes the specified sequence of characters from the end of this builder.
public void TrimSuffix(scoped ReadOnlySpan<char> value, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valueReadOnlySpan<char>The sequence of characters to remove.
comparisonTypeStringComparisonThe way to compare the sequences of characters.
TryCopyTo(Span<char>)
Tries to copy the represented string into the given Span<T>.
public readonly bool TryCopyTo(Span<char> destination)
Parameters
Returns
- bool
True, if the copy was successful, otherwise false.
Operators
implicit operator ValueStringBuilder(scoped ReadOnlySpan<char>)
Defines the implicit conversion of a ReadOnlySpan<T> to ValueStringBuilder.
public static implicit operator ValueStringBuilder(scoped ReadOnlySpan<char> fromString)
Parameters
fromStringReadOnlySpan<char>The string as initial buffer.
Returns
implicit operator ValueStringBuilder(string)
Defines the implicit conversion of a string to ValueStringBuilder.
public static implicit operator ValueStringBuilder(string fromString)
Parameters
fromStringstringThe string as initial buffer.