Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Text.​StringBuilder
Assembly: System.Runtime
Inheritance: object → StringBuilder
Represents a mutable string of characters. This class cannot be inherited.
Properties
public
int
Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the current instance.
public
char
Chars
public
int
Length
Gets or sets the length of the current <see cref="T:System.Text.StringBuilder" /> object.
public
int
MaxCapacity
Gets the maximum capacity of this instance.
Methods
public
StringBuilder
Append​(bool value)
value
The Boolean value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified Boolean value to this instance.
public
StringBuilder
Append​(byte value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 8-bit unsigned integer to this instance.
public
StringBuilder
Append​(char value)
value
The UTF-16-encoded code unit to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified <see cref="T:System.Char" /> object to this instance.
public
StringBuilder
Append​(Char* value,
int valueCount)
value
A pointer to an array of characters.
valueCount
The number of characters in the array.
Returns A reference to this instance after the append operation has completed.
Appends an array of Unicode characters starting at a specified address to this instance.
public
StringBuilder
Append​(char value,
int repeatCount)
value
The character to append.
repeatCount
The number of times to append <paramref name="value" /> .
Returns A reference to this instance after the append operation has completed.
Appends a specified number of copies of the string representation of a Unicode character to this instance.
public
StringBuilder
Append​(char[] value)
value
The array of characters to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of the Unicode characters in a specified array to this instance.
public
StringBuilder
Append​(char[] value,
int startIndex,
int charCount)
value
A character array.
startIndex
The starting position in <paramref name="value" /> .
charCount
The number of characters to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified subarray of Unicode characters to this instance.
public
StringBuilder
Append​(decimal value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified decimal number to this instance.
public
StringBuilder
Append​(double value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified double-precision floating-point number to this instance.
public
StringBuilder
Append​(IFormatProvider provider,
AppendInterpolatedStringHandler& handler)
public
StringBuilder
Append​(short value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 16-bit signed integer to this instance.
public
StringBuilder
Append​(int value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 32-bit signed integer to this instance.
public
StringBuilder
Append​(long value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 64-bit signed integer to this instance.
public
StringBuilder
Append​(object value)
value
The object to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified object to this instance.
public
StringBuilder
Append​(sbyte value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 8-bit signed integer to this instance.
public
StringBuilder
Append​(Single value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified single-precision floating-point number to this instance.
public
StringBuilder
Append​(string value)
value
The string to append.
Returns A reference to this instance after the append operation has completed.
Appends a copy of the specified string to this instance.
public
StringBuilder
Append​(string value,
int startIndex,
int count)
value
The string that contains the substring to append.
startIndex
The starting position of the substring within <paramref name="value" /> .
count
The number of characters in <paramref name="value" /> to append.
Returns A reference to this instance after the append operation has completed.
Appends a copy of a specified substring to this instance.
public
StringBuilder
Append​(StringBuilder value)
value
The string builder to append.
Returns A reference to this instance after the append operation is completed.
Appends the string representation of a specified string builder to this instance.
public
StringBuilder
Append​(StringBuilder value,
int startIndex,
int count)
value
The string builder that contains the substring to append.
startIndex
The starting position of the substring within <paramref name="value" /> .
count
The number of characters in <paramref name="value" /> to append.
Returns A reference to this instance after the append operation has completed.
Appends a copy of a substring within a specified string builder to this instance.
public
StringBuilder
Append​(ushort value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 16-bit unsigned integer to this instance.
public
StringBuilder
Append​(uint value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 32-bit unsigned integer to this instance.
public
StringBuilder
Append​(ulong value)
value
The value to append.
Returns A reference to this instance after the append operation has completed.
Appends the string representation of a specified 64-bit unsigned integer to this instance.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
string format,
object arg0)
provider
An object that supplies culture-specific formatting information.
format
A composite format string.
arg0
The object to format.
Returns A reference to this instance after the append operation has completed. After the append operation, this instance contains any data that existed before the operation, suffixed by a copy of <paramref name="format" /> in which any format specification is replaced by the string representation of <paramref name="arg0" /> .
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of a single argument using a specified format provider.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
string format,
object arg0,
object arg1)
provider
An object that supplies culture-specific formatting information.
format
A composite format string.
arg0
The first object to format.
arg1
The second object to format.
Returns A reference to this instance after the append operation has completed. After the append operation, this instance contains any data that existed before the operation, suffixed by a copy of <paramref name="format" /> where any format specification is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of two arguments using a specified format provider.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
string format,
object arg0,
object arg1,
object arg2)
provider
An object that supplies culture-specific formatting information.
format
A composite format string.
arg0
The first object to format.
arg1
The second object to format.
arg2
The third object to format.
Returns A reference to this instance after the append operation has completed. After the append operation, this instance contains any data that existed before the operation, suffixed by a copy of <paramref name="format" /> where any format specification is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of three arguments using a specified format provider.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
string format,
object[] args)
provider
An object that supplies culture-specific formatting information.
format
A composite format string.
args
An array of objects to format.
Returns A reference to this instance after the append operation has completed. After the append operation, this instance contains any data that existed before the operation, suffixed by a copy of <paramref name="format" /> where any format specification is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of a corresponding argument in a parameter array using a specified format provider.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
string format,
ReadOnlySpan`1 args)
public
StringBuilder
AppendFormat​(IFormatProvider provider,
CompositeFormat format,
object[] args)
provider
An object that supplies culture-specific formatting information.
format
A <see cref="T:System.Text.CompositeFormat" /> .
args
An array of objects to format.
Returns A reference to this instance after the append operation has completed.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance.
Each format item is replaced by the string representation of any of the arguments using a specified format provider.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
CompositeFormat format,
ReadOnlySpan`1 args)
public
StringBuilder
AppendFormat​(string format,
object arg0)
format
A composite format string.
arg0
An object to format.
Returns A reference to this instance with <paramref name="format" /> appended. Each format item in <paramref name="format" /> is replaced by the string representation of <paramref name="arg0" /> .
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of a single argument.
public
StringBuilder
AppendFormat​(string format,
object arg0,
object arg1)
format
A composite format string.
arg0
The first object to format.
arg1
The second object to format.
Returns A reference to this instance with <paramref name="format" /> appended. Each format item in <paramref name="format" /> is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of two arguments.
public
StringBuilder
AppendFormat​(string format,
object arg0,
object arg1,
object arg2)
format
A composite format string.
arg0
The first object to format.
arg1
The second object to format.
arg2
The third object to format.
Returns A reference to this instance with <paramref name="format" /> appended. Each format item in <paramref name="format" /> is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of three arguments.
public
StringBuilder
AppendFormat​(string format,
object[] args)
format
A composite format string.
args
An array of objects to format.
Returns A reference to this instance with <paramref name="format" /> appended. Each format item in <paramref name="format" /> is replaced by the string representation of the corresponding object argument.
Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of a corresponding argument in a parameter array.
public
StringBuilder
AppendFormat​(IFormatProvider provider,
CompositeFormat format,
TArg0 arg0)
public
StringBuilder
AppendFormat​(IFormatProvider provider,
CompositeFormat format,
TArg0 arg0,
TArg1 arg1)
public
StringBuilder
AppendFormat​(IFormatProvider provider,
CompositeFormat format,
TArg0 arg0,
TArg1 arg1,
TArg2 arg2)
public
StringBuilder
AppendJoin​(char separator,
object[] values)
separator
The character to use as a separator. <paramref name="separator" /> is included in the joined strings only if <paramref name="values" /> has more than one element.
values
An array that contains the strings to concatenate and append to the current instance of the string builder.
Returns A reference to this instance after the append operation has completed.
Concatenates the string representations of the elements in the provided array of objects, using the specified char separator between each member, then appends the result to the current instance of the string builder.
public
StringBuilder
AppendJoin​(char separator,
string[] values)
separator
The character to use as a separator. <paramref name="separator" /> is included in the joined strings only if <paramref name="values" /> has more than one element.
values
An array that contains the strings to concatenate and append to the current instance of the string builder.
Returns A reference to this instance after the append operation has completed.
Concatenates the strings of the provided array, using the specified char separator between each string, then appends the result to the current instance of the string builder.
public
StringBuilder
AppendJoin​(string separator,
object[] values)
separator
The string to use as a separator. <paramref name="separator" /> is included in the joined strings only if <paramref name="values" /> has more than one element.
values
An array that contains the strings to concatenate and append to the current instance of the string builder.
Returns A reference to this instance after the append operation has completed.
Concatenates the string representations of the elements in the provided array of objects, using the specified separator between each member, then appends the result to the current instance of the string builder.
public
StringBuilder
AppendJoin​(string separator,
string[] values)
separator
The string to use as a separator. <paramref name="separator" /> is included in the joined strings only if <paramref name="values" /> has more than one element.
values
An array that contains the strings to concatenate and append to the current instance of the string builder.
Returns A reference to this instance after the append operation has completed.
Concatenates the strings of the provided array, using the specified separator between each string, then appends the result to the current instance of the string builder.
public
StringBuilder
AppendJoin​(char separator,
Collections.Generic.IEnumerable`1 values)
public
StringBuilder
AppendJoin​(string separator,
Collections.Generic.IEnumerable`1 values)
public
StringBuilder
AppendLine​() Returns A reference to this instance after the append operation has completed.
Appends the default line terminator to the end of the current <see cref="T:System.Text.StringBuilder" /> object.
public
StringBuilder
AppendLine​(IFormatProvider provider,
AppendInterpolatedStringHandler& handler)
public
StringBuilder
AppendLine​(string value)
value
The string to append.
Returns A reference to this instance after the append operation has completed.
Appends a copy of the specified string followed by the default line terminator to the end of the current <see cref="T:System.Text.StringBuilder" /> object.
public
StringBuilder
Clear​() Returns An object whose <see cref="P:System.Text.StringBuilder.Length" /> is 0 (zero).
Removes all characters from the current <see cref="T:System.Text.StringBuilder" /> instance.
public
void
CopyTo​(int sourceIndex,
char[] destination,
int destinationIndex,
int count)
sourceIndex
The starting position in this instance where characters will be copied from. The index is zero-based.
destination
The array where characters will be copied.
destinationIndex
The starting position in <paramref name="destination" /> where characters will be copied. The index is zero-based.
count
The number of characters to be copied.
Copies the characters from a specified segment of this instance to a specified segment of a destination <see cref="T:System.Char" /> array.
public
int
EnsureCapacity​(int capacity)
capacity
The minimum capacity to ensure.
Returns The new capacity of this instance.
Ensures that the capacity of this instance of <see cref="T:System.Text.StringBuilder" /> is at least the specified value.
public
bool
Equals​(StringBuilder sb)
sb
An object to compare with this instance, or <see langword="null" /> .
Returns <see langword="true" /> if this instance and <paramref name="sb" /> have equal string, <see cref="P:System.Text.StringBuilder.Capacity" /> , and <see cref="P:System.Text.StringBuilder.MaxCapacity" /> values; otherwise, <see langword="false" /> .
Returns a value indicating whether this instance is equal to a specified object.
public
ChunkEnumerator
GetChunks​() Returns An enumerator for the chunks in the <see langword="ReadOnlyMemory<Char>" /> .
Returns an object that can be used to iterate through the chunks of characters represented in a <see langword="ReadOnlyMemory<Char>" /> created from this <see cref="T:System.Text.StringBuilder" /> instance.
public
StringBuilder
Insert​(int index,
bool value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a Boolean value into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
byte value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified 8-bit unsigned integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
char value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified Unicode character into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
char[] value)
index
The position in this instance where insertion begins.
value
The character array to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified array of Unicode characters into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
char[] value,
int startIndex,
int charCount)
index
The position in this instance where insertion begins.
value
A character array.
startIndex
The starting index within <paramref name="value" /> .
charCount
The number of characters to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified subarray of Unicode characters into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
decimal value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a decimal number into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
double value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a double-precision floating-point number into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
short value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified 16-bit signed integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
int value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified 32-bit signed integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
long value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a 64-bit signed integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
object value)
index
The position in this instance where insertion begins.
value
The object to insert, or <see langword="null" /> .
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of an object into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
sbyte value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a specified 8-bit signed integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
Single value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a single-precision floating point number into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
string value)
index
The position in this instance where insertion begins.
value
The string to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts a string into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
string value,
int count)
index
The position in this instance where insertion begins.
value
The string to insert.
count
The number of times to insert <paramref name="value" /> .
Returns A reference to this instance after insertion has completed.
Inserts one or more copies of a specified string into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
ushort value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a 16-bit unsigned integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
uint value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a 32-bit unsigned integer into this instance at the specified character position.
public
StringBuilder
Insert​(int index,
ulong value)
index
The position in this instance where insertion begins.
value
The value to insert.
Returns A reference to this instance after the insert operation has completed.
Inserts the string representation of a 64-bit unsigned integer into this instance at the specified character position.
public
StringBuilder
Remove​(int startIndex,
int length)
startIndex
The zero-based position in this instance where removal begins.
length
The number of characters to remove.
Returns A reference to this instance after the excise operation has completed.
Removes the specified range of characters from this instance.
public
StringBuilder
Replace​(char oldChar,
char newChar)
oldChar
The character to replace.
newChar
The character that replaces <paramref name="oldChar" /> .
Returns A reference to this instance with <paramref name="oldChar" /> replaced by <paramref name="newChar" /> .
Replaces all occurrences of a specified character in this instance with another specified character.
public
StringBuilder
Replace​(char oldChar,
char newChar,
int startIndex,
int count)
oldChar
The character to replace.
newChar
The character that replaces <paramref name="oldChar" /> .
startIndex
The position in this instance where the substring begins.
count
The length of the substring.
Returns A reference to this instance with <paramref name="oldChar" /> replaced by <paramref name="newChar" /> in the range from <paramref name="startIndex" /> to <paramref name="startIndex" /> + <paramref name="count" /> -1.
Replaces, within a substring of this instance, all occurrences of a specified character with another specified character.
public
StringBuilder
Replace​(ReadOnlySpan`1 oldValue,
ReadOnlySpan`1 newValue,
int startIndex,
int count)
public
StringBuilder
Replace​(string oldValue,
string newValue)
oldValue
The string to replace.
newValue
The string that replaces <paramref name="oldValue" /> , or <see langword="null" /> .
Returns A reference to this instance with all instances of <paramref name="oldValue" /> replaced by <paramref name="newValue" /> .
Replaces all occurrences of a specified string in this instance with another specified string.
public
StringBuilder
Replace​(string oldValue,
string newValue,
int startIndex,
int count)
oldValue
The string to replace.
newValue
The string that replaces <paramref name="oldValue" /> , or <see langword="null" /> .
startIndex
The position in this instance where the substring begins.
count
The length of the substring.
Returns A reference to this instance with all instances of <paramref name="oldValue" /> replaced by <paramref name="newValue" /> in the range from <paramref name="startIndex" /> to <paramref name="startIndex" /> + <paramref name="count" /> - 1.
Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.
public
string
ToString​() Returns A string whose value is the same as this instance.
Converts the value of this instance to a <see cref="T:System.String" /> .
public
string
ToString​(int startIndex,
int length)
startIndex
The starting position of the substring in this instance.
length
The length of the substring.
Returns A string whose value is the same as the specified substring of this instance.
Converts the value of a substring of this instance to a <see cref="T:System.String" /> .
public
bool
Equals​(object obj)
Inherited from object
obj
The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .