[Serializable] |
Most of the methods that modify an instance of this class return a reference to that same instance. Since a reference to the instance is returned, you can call a method or property on the reference. This can be convenient if you want to write a single statement that chains successive operations one after another.
The capacity of a StringBuilder is the maximum number of characters the instance can store at any given time, and is greater than or equal to the length of the string representation of the value of the instance. The capacity can be increased or decreased with the StringBuilder.Capacity property or StringBuilder.EnsureCapacity method, but it cannot be less than the value of the StringBuilder.Length property.
A StringBuilder can allocate more memory as needed to store characters when the value of an instance is enlarged, and the capacity is adjusted accordingly. A default capacity is used if no capacity is specified when an instance of StringBuilder is initialized.
A StringBuilder can allocate more memory as needed to store characters when the string value of an instance is enlarged. The amount of memory allocated is implementation-specific. An ArgumentOutOfRangeException is thrown if the amount of memory required is greater than the maximum capacity.
The individual characters in the value of a StringBuilder can be accessed with the StringBuilder.Chars property. Index positions start from zero.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the StringBuilder class. |
ctor #2 | Overloaded:.ctor(int capacity) Initializes a new instance of the StringBuilder class using the specified capacity. |
ctor #3 | Overloaded:.ctor(string value) Initializes a new instance of the StringBuilder class using the specified string. |
ctor #4 | Overloaded:.ctor(int capacity, int maxCapacity) Initializes a new instance of the StringBuilder class that starts with a specified capacity and can grow to a specified maximum. |
ctor #5 | Overloaded:.ctor(string value, int capacity) Initializes a new instance of the StringBuilder class using the specified string and capacity. |
ctor #6 | Overloaded:.ctor(string value, int startIndex, int length, int capacity) Initializes a new instance of the StringBuilder class from the specified substring and capacity. |
Capacity | Read-write Gets or sets the maximum number of characters that can be contained in the memory allocated by the current instance. |
Chars | Read-write Gets or sets the character at the specified character position in this instance. |
Length | Read-write Gets or sets the length of this instance. |
MaxCapacity | Read-only Gets the maximum capacity of this instance. |
Append | Overloaded:Append(bool value) Appends the string representation of a specified Boolean value to the end of this instance. |
Append | Overloaded:Append(byte value) Appends the string representation of a specified 8-bit unsigned integer to the end of this instance. |
Append | Overloaded:Append(char value) Appends the string representation of a specified Unicode character to the end of this instance. |
Append | Overloaded:Append(char[] value) Appends the string representation of the Unicode characters in a specified array to the end of this instance. |
Append | Overloaded:Append(decimal value) Appends the string representation of a specified decimal number to the end of this instance. |
Append | Overloaded:Append(double value) Appends the string representation of a specified double-precision floating-point number to the end of this instance. |
Append | Overloaded:Append(short value) Appends the string representation of a specified 16-bit signed integer to the end of this instance. |
Append | Overloaded:Append(int value) Appends the string representation of a specified 32-bit signed integer to the end of this instance. |
Append | Overloaded:Append(long value) Appends the string representation of a specified 64-bit signed integer to the end of this instance. |
Append | Overloaded:Append(object value) Appends the string representation of a specified object to the end of this instance. |
Append | Overloaded:Append(sbyte value) Appends the string representation of a specified 8-bit signed integer to the end of this instance. |
Append | Overloaded:Append(float value) Appends the string representation of a specified single-precision floating-point number to the end of this instance. |
Append | Overloaded:Append(string value) Appends a copy of the specified string to the end of this instance. |
Append | Overloaded:Append(ushort value) Appends the string representation of a specified 16-bit unsigned integer to the end of this instance. |
Append | Overloaded:Append(uint value) Appends the string representation of a specified 32-bit unsigned integer to the end of this instance. |
Append | Overloaded:Append(ulong value) Appends the string representation of a specified 64-bit unsigned integer to the end of this instance. |
Append | Overloaded:Append(char value, int repeatCount) Appends a specified number of copies of the string representation of a Unicode character to the end of this instance. |
Append | Overloaded:Append(char[] value, int startIndex, int charCount) Appends the string representation of a specified subarray of Unicode characters to the end of this instance. |
Append | Overloaded:Append(string value, int startIndex, int count) Appends a copy of a specified substring to the end of this instance. |
AppendFormat | Overloaded:AppendFormat(string format, object arg0) Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument. |
AppendFormat | Overloaded:AppendFormat(string format, params object[] args) Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument. |
AppendFormat | Overloaded:AppendFormat(IFormatProvider provider, string format, params object[] args) Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument. |
AppendFormat | Overloaded:AppendFormat(string format, object arg0, object arg1) Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument. |
AppendFormat | Overloaded:AppendFormat(string format, object arg0, object arg1, object arg2) Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument. |
EnsureCapacity | Ensures that the capacity of this instance of StringBuilder is at least the specified value. |
Equals (inherited from System.Object) |
Overloaded:Equals(object obj) See base class member description: System.Object.EqualsDerived from System.Object, the primary base class for all objects. |
Equals | Overloaded:Equals(StringBuilder sb) Returns a value indicating whether this instance is equal to a specified object. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
Insert | Overloaded:Insert(int index, bool value) Inserts the string representation of a Boolean value into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, byte value) Inserts the string representation of a specified 8-bit unsigned integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, char value) Inserts the string representation of a specified Unicode character into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, char[] value) Inserts the string representation of a specified array of Unicode characters into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, decimal value) Inserts the string representation of a decimal number into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, double value) Inserts the string representation of a double-precision floating-point number into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, short value) Inserts the string representation of a specified 16-bit signed integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, int value) Inserts the string representation of a specified 32-bit signed integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, long value) Inserts the string representation of a 64-bit signed integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, object value) Inserts the string representation of an object into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, sbyte value) Inserts the string representation of a specified 8-bit signed integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, float value) Inserts the string representation of a single-precision floating point number into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, string value) Inserts a string into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, ushort value) Inserts the string representation of a 16-bit unsigned integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, uint value) Inserts the string representation of a 32-bit unsigned integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, ulong value) Inserts the string representation of a 64-bit unsigned integer into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, string value, int count) Inserts one or more copies of a specified string into this instance at the specified character position. |
Insert | Overloaded:Insert(int index, char[] value, int startIndex, int charCount) Inserts the string representation of a specified subarray of Unicode characters into this instance at the specified character position. |
Remove | Removes the specified range of characters from this instance. |
Replace | Overloaded:Replace(char oldChar, char newChar) Replaces all occurrences of a specified character in this instance with another specified character. |
Replace | Overloaded:Replace(string oldValue, string newValue) Replaces all occurrences of a specified substring in this instance with another specified string. |
Replace | Overloaded:Replace(char oldChar, char newChar, int startIndex, int count) Replaces all occurrences of a specified character in a substring of this instance with another specified character. |
Replace | Overloaded:Replace(string oldValue, string newValue, int startIndex, int count) Replaces all occurrences of a specified string in a substring of this instance with another specified string. |
ToString | Overloaded:ToString() Overridden: Converts this instance to a String. |
ToString | Overloaded:ToString(int startIndex, int length) Converts a substring of the current StringBuilder to a String. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public StringBuilder(); |
public StringBuilder( |
capacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. |
public StringBuilder( |
value
capacity
maxCapacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | maxCapacity is less than one, capacity is less than zero, or capacity is greater than maxCapacity. |
value
capacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. |
value
startIndex
length
capacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. -or- startIndex plus length is not a position within value. |
ArgumentNullException | value is null or the empty string and startIndex, length, and capacity are not zero. |
public int Capacity {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | Capacity is less than the current length of this instance. -or- Capacity is greater than the maximum capacity. |
The StringBuilder dynamically allocates more space when required and increases StringBuilder.Capacity accordingly. For performance reasons, a StringBuilder might allocate more memory than needed. The amount of memory allocated is implementation-specific.
No member name
public char this[int index] {get; set;}
|
index
public int Length {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The value specified for a set operation is less than zero or greater than Int32.MaxValue. |
public int MaxCapacity {get;}
|
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
The capacity is adjusted as needed.
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
The capacity is adjusted as needed.
[CLSCompliant(false)] |
value
public StringBuilder Append( |
value
public StringBuilder Append( |
value
The capacity is adjusted as needed.
[CLSCompliant(false)] |
value
[CLSCompliant(false)] |
value
[CLSCompliant(false)] |
value
public StringBuilder Append( |
value
repeatCount
public StringBuilder Append( |
value
startIndex
charCount
Exception Type | Condition |
---|---|
ArgumentNullException | value is null, and startIndex and charCount are not zero. |
ArgumentOutOfRangeException | charCount is less than zero. -or- startIndex is less than zero. -or- startIndex + charCount is less than the length of value. |
The capacity is adjusted as needed.
public StringBuilder Append( |
value
startIndex
count
Exception Type | Condition |
---|---|
ArgumentNullException | value is null, and startIndex and count are not zero. |
ArgumentOutOfRangeException | count less than zero. -or- startIndex less than zero. -or- startIndex + count is less than the length of value. |
The capacity is adjusted as needed.
public StringBuilder AppendFormat( |
format
arg0
Exception Type | Condition |
---|---|
ArgumentNullException | arg0 is null. |
FormatException | format is invalid. |
To Pad With Spaces: You can define a region within the string argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.
Object.ToString is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the Object.ToString method of the argument specified by N is used to replace the format specification. If M is given, then the result of Object.ToString is padded with spaces as described above.
If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg[0] is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
public StringBuilder AppendFormat( |
format
args
Exception Type | Condition |
---|---|
ArgumentNullException | Any of the object parameters is null. |
FormatException | format is invalid. |
To Pad With Spaces: You can define a region within the string argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.
Object.ToString is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the Object.ToString method of the argument specified by N is used to replace the format specification. If M is given, then the result of Object.ToString is padded with spaces as described above.
If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg[0] is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
public StringBuilder AppendFormat( |
provider
format
args
Exception Type | Condition |
---|---|
ArgumentNullException | Any of the object parameters is null. |
FormatException | format is invalid. |
The provider parameter specifies the format provider that the NumberFormatInfo is obtained from. NumberFormatInfo supplies information such as the characters to use for decimal and group separators, and determines the spelling and placement of currency symbols in monetary values. If provider is null, the numeric format information is obtained from the current culture.
To Pad With Spaces: You can define a region within the string argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.
Object.ToString is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the Object.ToString method of the argument specified by N is used to replace the format specification. If M is given, then the result of Object.ToString is padded with spaces as described above.
If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg[0] is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
public StringBuilder AppendFormat( |
format
arg0
arg1
Exception Type | Condition |
---|---|
ArgumentNullException | Any of the object parameters is null. |
FormatException | format is invalid. |
To Pad With Spaces: You can define a region within the string argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.
Object.ToString is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the Object.ToString method of the argument specified by N is used to replace the format specification. If M is given, then the result of Object.ToString is padded with spaces as described above.
If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg[0] is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
public StringBuilder AppendFormat( |
format
arg0
arg1
arg2
Exception Type | Condition |
---|---|
ArgumentNullException | Any of the object parameters is null. |
FormatException | format is invalid. |
To Pad With Spaces: You can define a region within the string argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.
Object.ToString is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the Object.ToString method of the argument specified by N is used to replace the format specification. If M is given, then the result of Object.ToString is padded with spaces as described above.
If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg[0] is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
capacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. |
public bool Equals( |
sb
~StringBuilder(); |
public virtual int GetHashCode(); |
public Type GetType(); |
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. |
If value is null, the StringBuilder is not changed.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is greater than the length of this instance. -or- index is less than zero. |
If value is null, the value of this instance is unchanged.
[CLSCompliant(false)] |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value equals String.Empty, the StringBuilder is not changed. If value is null, the empty string is inserted.
[CLSCompliant(false)] |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
[CLSCompliant(false)] |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
[CLSCompliant(false)] |
index
value
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index is not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
If value is null, the empty string is inserted.
public StringBuilder Insert( |
index
value
count
Exception Type | Condition |
---|---|
ArgumentNullException | value is null and index and count are not zero. |
ArgumentOutOfRangeException | index is less than zero or greater than the length of this instance. -or- count is less than one. |
public StringBuilder Insert( |
index
value
startIndex
charCount
Exception Type | Condition |
---|---|
ArgumentNullException | value is null, and startIndex and charCount are not zero. |
ArgumentOutOfRangeException | index, startIndex, or charCount is less than zero. -or- index is greater than the length of this instance. -or- startIndex plus charCount is not a position within value. |
protected object MemberwiseClone(); |
public StringBuilder Remove( |
startIndex
length
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | If startIndex or length is less than zero, or startIndex + length is greater than the length of this instance. |
Replace(string oldValue,
null)
can be used to remove all instances of a string from a StringBuilder.
public StringBuilder Replace( |
oldChar
newChar
public StringBuilder Replace( |
oldValue
newValue
Exception Type | Condition |
---|---|
ArgumentNullException | oldValue is null. |
ArgumentException | The length of oldvalue is zero. |
public StringBuilder Replace( |
oldChar
newChar
startIndex
count
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex + count is greater than the length of the value of this instance. -or- startIndex or count is less than zero. |
public StringBuilder Replace( |
oldValue
newValue
startIndex
count
Exception Type | Condition |
---|---|
ArgumentNullException | oldValue is null. |
ArgumentException | The length of oldvalue is zero. |
ArgumentOutOfRangeException | startIndex or count is less than zero. -or- startIndex plus count indicates a character position not within oldValue. |
public override string ToString(); |
startIndex
length
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | startIndex or length is less than zero. -or- The sum of startIndex and length is greater than the length of the current instance. |