Difference between revisions of "StringBuilder class"

From Catglobe Wiki
Jump to: navigation, search
 
Line 12: Line 12:
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Clear</nowiki>|Description=<nowiki>Clear content, but maintain buffer.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Clear</nowiki>|Description=<nowiki>Clear content, but maintain buffer.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>}}
+
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The index used to lookup the char at that index.</nowiki>}}
 
|Description=<nowiki>Get the char at the given index.</nowiki>}}
 
|Description=<nowiki>Get the char at the given index.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Remove</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Remove</nowiki>|Parameters=
Line 24: Line 24:
 
|Description=<nowiki>Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.</nowiki>}}
 
|Description=<nowiki>Replaces, within a substring of this instance, all occurrences of a specified string with another specified string.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>The value to set.</nowiki>}}
+
{{CGscriptParameters_Template|Type=int|Name=<nowiki>index</nowiki>|Description=<nowiki>The index used to lookup the char at that index.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=object|Name=<nowiki>value</nowiki>|Description=<nowiki>The value to set.</nowiki>}}
 
|Description=<nowiki>Set the char at the given index to the value given.</nowiki>}}
 
|Description=<nowiki>Set the char at the given index to the value given.</nowiki>}}
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>Substring</nowiki>|Parameters=
 
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>Substring</nowiki>|Parameters=
Line 35: Line 35:
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
}}
 
}}
 
 
=== Examples ===
 
=== Examples ===
 
<source lang="javascript">
 
<source lang="javascript">

Latest revision as of 10:42, 10 September 2020

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