Difference between revisions of "StringBuilder class"

From Catglobe Wiki
Jump to: navigation, search
Line 10: Line 10:
 
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>AppendFormat</nowiki>|Parameters={{CGscriptParameters_Template|Type=params AnyType|Name=params AnyType|Description=}}
 
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>AppendFormat</nowiki>|Parameters={{CGscriptParameters_Template|Type=params AnyType|Name=params AnyType|Description=}}
 
|Description=<nowiki>Format the first param with the other parameters given and append to current string</nowiki>}}
 
|Description=<nowiki>Format the first param with the other parameters given and append to current string</nowiki>}}
 +
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Clear</nowiki>|Description=<nowiki>Clear content, but maintain buffer.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptParameters_Template|Type=number|Name=<nowiki>index</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>}}
 
{{CGscriptParameters_Template|Type=number|Name=<nowiki>index</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>}}
Line 30: Line 31:
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
 
|Properties=
 
|Properties=
 +
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Length</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set length of string.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}

Revision as of 10:07, 3 July 2015

StringBuilder



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

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.
  • string this[] { get; }(number index "The key used to lookup the value.") - Get the char at the given index.
  • StringBuilder Remove(number startIndex "The zero-based position in this instance where removal begins.", number 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.", number startIndex "The position in this instance where the substring begins.", number 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; }(number index "The key used to lookup the value.", string value "The value to set.") - Set the char at the given index to the value given.
  • string Substring(number startIndex "The position in this instance where the substring begins.", number length "The length of the substring.") - Returns a substring in the string.
  • string ToString() - The string representation of the object.

Properties

  • number Length { get; set; } - Get/Set length of string.
  • string ObjectTypeName { get; } - The name of the type of 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