Class StringBuilder
Represents a mutable string of characters. This class cannot be inherited.
public sealed class StringBuilder- Inheritance
- 
      
      StringBuilder
- Inherited Members
- Extension Methods
Remarks
This is a port of the full .NET Framework StringBuilder class.
Contributed to the .NETMF code base by Julius Friedman.
Constructors
StringBuilder()
Initializes a new instance of the StringBuilder class.
public StringBuilder()StringBuilder(int)
Initializes a new instance of the StringBuilder class using the specified capacity.
public StringBuilder(int capacity)Parameters
- capacityint
- The suggested starting size of this instance. 
StringBuilder(int, int)
Initializes a new instance of the StringBuilder class that starts with a specified capacity and can grow to a specified maximum.
public StringBuilder(int capacity, int maxCapacity)Parameters
- capacityint
- The suggested starting size of the StringBuilder. 
- maxCapacityint
- The maximum number of characters the current string can contain. 
Exceptions
- ArgumentOutOfRangeException
- If - capacityis less than zero,- maxCapacityis less than one, or- capacityis greater than- maxCapacity.
StringBuilder(string)
Initializes a new instance of the StringBuilder class using the specified string.
public StringBuilder(string value)Parameters
- valuestring
- The string used to initialize the value of the instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). 
StringBuilder(string, int)
Initializes a new instance of the StringBuilder class using the specified string and capacity.
public StringBuilder(string value, int capacity)Parameters
- valuestring
- The string used to initialize the value of the instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). 
- capacityint
- The suggested starting size of the StringBuilder. 
StringBuilder(string, int, int, int)
Initializes a new instance of the StringBuilder class from the specified substring and capacity.
public StringBuilder(string value, int startIndex, int length, int capacity)Parameters
- valuestring
- The string that contains the substring used to initialize the value of this instance. If value is null, the new StringBuilder will contain the empty string (that is, it contains Empty). 
- startIndexint
- The position within value where the substring begins. 
- lengthint
- The number of characters in the substring. 
- capacityint
- The suggested starting size of the StringBuilder. 
Exceptions
- ArgumentOutOfRangeException
- If - capacityis less than zero,- lengthis less than zero,- startIndexis less than zero, or- startIndexis greater than the length of- valueminus- length.
Properties
Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the current instance.
public int Capacity { get; set; }Property Value
- int
- The maximum number of characters that can be contained in the memory allocated by the current instance. Its value can range from Length to MaxCapacity. 
Exceptions
- ArgumentOutOfRangeException
- The value specified for a set operation is less than the current length of this instance. - -or- - The value specified for a set operation is greater than the maximum capacity. 
this[int]
Gets or sets the character at the specified character position in this instance.
public char this[int index] { get; set; }Parameters
- indexint
- The position of the character. 
Property Value
- char
- The Unicode character at position index. 
Exceptions
- IndexOutOfRangeException
- indexis outside the bounds of this instance while getting a character.
- ArgumentOutOfRangeException
- indexis outside the bounds of this instance while setting a character.
Length
Gets or sets the length of the current StringBuilder object.
public int Length { get; set; }Property Value
- int
- The length of this instance. 
Exceptions
- ArgumentOutOfRangeException
- If Length is set to a value that is less than zero or greater than MaxCapacity. 
MaxCapacity
Gets the maximum capacity of this instance.
public int MaxCapacity { get; }Property Value
- int
- The maximum number of characters this instance can hold. 
Methods
Append(bool)
Appends the string representation of a specified bool value to this instance.
public StringBuilder Append(bool value)Parameters
- valuebool
- The Boolean value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(byte)
Appends the string representation of a specified 8-bit unsigned integer to this instance.
public StringBuilder Append(byte value)Parameters
- valuebyte
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(char)
Appends the string representation of a specified Unicode character to this instance.
public StringBuilder Append(char value)Parameters
- valuechar
- The UTF-16-encoded code unit to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(char, int)
Appends a specified number of copies of the string representation of a Unicode character to this instance.
public StringBuilder Append(char value, int repeatCount)Parameters
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(char[])
Appends the string representation of the Unicode characters in a specified array to this instance.
public StringBuilder Append(char[] value)Parameters
- valuechar[]
- The array of characters to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Remarks
This method appends all the characters in the specified array to the current instance in the same order as they appear in value. If value is null, no changes are made.
Append(char[], int, int)
Appends the string representation of a specified subarray of Unicode characters to this instance
public StringBuilder Append(char[] value, int startIndex, int charCount)Parameters
- valuechar[]
- A character array. 
- startIndexint
- The starting position in value. 
- charCountint
- The number of characters to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(double)
Appends the string representation of a specified double-precision floating-point number to this instance.
public StringBuilder Append(double value)Parameters
- valuedouble
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(short)
Appends the string representation of a specified 16-bit signed integer to this instance.
public StringBuilder Append(short value)Parameters
- valueshort
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(int)
Appends the string representation of a specified 32-bit signed integer to this instance.
public StringBuilder Append(int value)Parameters
- valueint
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(long)
Appends the string representation of a specified 64-bit unsigned integer to this instance.
public StringBuilder Append(long value)Parameters
- valuelong
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(object)
Appends the string representation of a specified object to this instance.
public StringBuilder Append(object value)Parameters
- valueobject
- The object to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(sbyte)
Appends the string representation of a specified 8-bit signed integer to this instance.
public StringBuilder Append(sbyte value)Parameters
- valuesbyte
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(float)
Appends the string representation of a specified double-precision floating-point number to this instance.
public StringBuilder Append(float value)Parameters
- valuefloat
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(string)
Appends a copy of the specified string to this instance.
public StringBuilder Append(string value)Parameters
- valuestring
- The string to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(string, int, int)
Appends a copy of a specified substring to this instance.
public StringBuilder Append(string value, int startIndex, int count)Parameters
- valuestring
- The string that contains the substring to append. 
- startIndexint
- The starting position of the substring within value. 
- countint
- The number of characters in value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(ushort)
Appends the string representation of a specified 16-bit unsigned integer to this instance.
public StringBuilder Append(ushort value)Parameters
- valueushort
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(uint)
Appends the string representation of a specified 32-bit unsigned integer to this instance.
public StringBuilder Append(uint value)Parameters
- valueuint
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
Append(ulong)
Appends the string representation of a specified 64-bit unsigned integer to this instance.
public StringBuilder Append(ulong value)Parameters
- valueulong
- The value to append. 
Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
AppendLine()
Appends the default line terminator to the end of the current StringBuilder object.
public StringBuilder AppendLine()Returns
- StringBuilder
- A reference to this instance after the append operation has completed. 
AppendLine(string)
Appends a copy of the specified string followed by the default line terminator to the end of the current StringBuilder object.
public StringBuilder AppendLine(string str)Parameters
- strstring
- A reference to this instance after the append operation has completed. 
Returns
Clear()
Removes all characters from the current StringBuilder instance.
public StringBuilder Clear()Returns
- StringBuilder
- An object whose Length is 0 (zero). 
Insert(int, char[], int, int)
Inserts the string representation of a specified subarray of Unicode characters into this instance at the specified character position.
public StringBuilder Insert(int index, char[] value, int startIndex, int charCount)Parameters
- indexint
- The position in this instance where insertion begins. 
- valuechar[]
- A character array. 
- startIndexint
- The starting index within value. 
- charCountint
- The number of characters to insert. 
Returns
- StringBuilder
- A reference to this instance after the insert operation has completed. 
Insert(int, string, int)
Inserts one or more copies of a specified string into this instance at the specified character position.
public StringBuilder Insert(int index, string value, int count)Parameters
- indexint
- The position in this instance where insertion begins. 
- valuestring
- The string to insert. 
- countint
- The number of times to insert value. 
Returns
- StringBuilder
- A reference to this instance after insertion has completed. 
Remove(int, int)
Removes the specified range of characters from this instance.
public StringBuilder Remove(int startIndex, int length)Parameters
- startIndexint
- The zero-based position in this instance where removal begins. 
- lengthint
- The number of characters to remove. 
Returns
- StringBuilder
- A reference to this instance after the excise operation has completed. 
Replace(char, char)
Replaces all occurrences of a specified character in this instance with another specified character.
public StringBuilder Replace(char oldChar, char newChar)Parameters
Returns
- StringBuilder
- A reference to this instance with - oldCharreplaced by- newChar.
Replace(char, char, int, int)
Replaces, within a substring of this instance, all occurrences of a specified character with another specified character.
public StringBuilder Replace(char oldChar, char newChar, int startIndex, int count)Parameters
- oldCharchar
- The character to replace. 
- newCharchar
- The character that replaces - oldChar.
- startIndexint
- The position in this instance where the substring begins. 
- countint
- The length of the substring. 
Returns
- StringBuilder
- A reference to this instance with - oldCharreplaced by- newCharin the range from- startIndexto- startIndex+- count- 1.
Replace(string, string)
Replaces all occurrences of a specified string in this instance with another specified string.
public StringBuilder Replace(string oldValue, string newValue)Parameters
Returns
- StringBuilder
- A reference to this instance with all instances of - oldValuereplaced by- newValue.
Replace(string, string, int, int)
Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.
public StringBuilder Replace(string oldValue, string newValue, int startIndex, int count)Parameters
- oldValuestring
- The string to replace. 
- newValuestring
- The string that replaces - oldValue, or null.
- startIndexint
- The position in this instance where the substring begins. 
- countint
- The length of the substring. 
Returns
- StringBuilder
- A reference to this instance with all instances of - oldValuereplaced by- newValuein the range from- startIndexto- startIndex+- count- 1.
ToString()
Converts the value of this instance to a String. (Overrides ToString()().)
public override string ToString()Returns
- string
- A string whose value is the same as this instance. 
ToString(int, int)
Converts the value of a substring of this instance to a string.
public string ToString(int startIndex, int length)Parameters
- startIndexint
- The starting position of the substring in this instance. 
- lengthint
- The length of the substring. 
Returns
- string
- A string whose value is the same as the specified substring of this instance.