StringBuilder class

From Catglobe Wiki
Jump to: navigation, search

StringBuilder



An equivalent to the stringbuilder class in dotnet, in that it is not invariant, and thus manipulations are fast.

Parent class

Inherits from object

Constructors

  • () - Create a new empty string

Methods

  • StringBuilder Append(string str "String to append") - Append to current string
  • StringBuilder AppendFormat(params AnyType) - Format the first param with the other parameters given and append to current string
  • Empty Clear() - Clear content, but maintain buffer.
  • object this[] { get; }(int index "The index used to lookup the char at that index.") - Get the char at the given index.
  • StringBuilder Remove(int startIndex "The zero-based position in this instance where removal begins.", int length "The number of characters to remove") - Removes the specified range of characters from this instance.
  • StringBuilder Replace(string oldValue "The string to replace.", string newValue "The string that replaces oldValue or Empty.") - Replaces all occurrences of a specified string in this instance with another specified string.
  • StringBuilder Replace(string oldValue "The string to replace.", string newValue "The string that replaces oldValue or Empty.", int startIndex "The position in this instance where the substring begins.", int count "The length of the substring.") - Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.
  • Empty this[] { set; }(int index "The index used to lookup the char at that index.", object value "The value to set.") - Set the char at the given index to the value given.
  • string Substring(int startIndex "The position in this instance where the substring begins.", int length "The length of the substring.") - Returns a substring in the string.
  • string ToString() - The string representation of the object.

Properties

  • int Length { get; set; } - Get/Set length of string.
  • string ObjectTypeName { get; } - The name of the type of object.
  • (From object) TypeInformation TypeInformation { get; } - Get information about this class.

Examples

String s = "My name is: {0} {1} {2}";
String firstName = "Nam";
String middleName = "Van";
String lastName = "Nguyen";

StringBuilder sb;
sb.Append("Hello! ");
sb.AppendFormat(s, firstName, middleName, lastName);
print(sb.ToString());  // Hello! My name is: Nam Van Nguyen