Difference between revisions of "StringBuilder class"
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
|Name=<nowiki>StringBuilder</nowiki> | |Name=<nowiki>StringBuilder</nowiki> | ||
|Description=<nowiki>An equivalent to the stringbuilder class in dotnet, in that it is not invariant, and thus manipulations are fast.</nowiki> | |Description=<nowiki>An equivalent to the stringbuilder class in dotnet, in that it is not invariant, and thus manipulations are fast.</nowiki> | ||
− | |Constructors= | + | |InheritsFrom=object|Constructors= |
{{CGscriptConstructors_Template|Description=<nowiki>Create a new empty string</nowiki>}} | {{CGscriptConstructors_Template|Description=<nowiki>Create a new empty string</nowiki>}} | ||
|Methods= | |Methods= | ||
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= | + | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Clear</nowiki>|Description=<nowiki>Clear content, but maintain buffer.</nowiki>}} |
− | {{CGscriptParameters_Template|Type= | + | {{CGscriptMethods_Template|ReturnType=object|Name=<nowiki>this[] { get; }</nowiki>|Parameters= |
+ | {{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= | ||
− | {{CGscriptParameters_Template|Type= | + | {{CGscriptParameters_Template|Type=int|Name=<nowiki>startIndex</nowiki>|Description=<nowiki>The zero-based position in this instance where removal begins.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>length</nowiki>|Description=<nowiki>The number of characters to remove</nowiki>}} |
|Description=<nowiki>Removes the specified range of characters from this instance.</nowiki>}} | |Description=<nowiki>Removes the specified range of characters from this instance.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Replace</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Replace</nowiki>|Parameters= | ||
Line 20: | Line 21: | ||
|Description=<nowiki>Replaces all occurrences of a specified string in this instance with another specified string.</nowiki>}} | |Description=<nowiki>Replaces all occurrences of a specified string in this instance with another specified string.</nowiki>}} | ||
{{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Replace</nowiki>|Parameters= | {{CGscriptMethods_Template|ReturnType=StringBuilder|Name=<nowiki>Replace</nowiki>|Parameters= | ||
− | {{CGscriptParameters_Template|Type=string|Name=<nowiki>oldValue</nowiki>|Description=<nowiki>The string to replace.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>newValue</nowiki>|Description=<nowiki>The string that replaces oldValue or Empty.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type= | + | {{CGscriptParameters_Template|Type=string|Name=<nowiki>oldValue</nowiki>|Description=<nowiki>The string to replace.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>newValue</nowiki>|Description=<nowiki>The string that replaces oldValue or Empty.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>startIndex</nowiki>|Description=<nowiki>The position in this instance where the substring begins.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>count</nowiki>|Description=<nowiki>The length of the substring.</nowiki>}} |
|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= | + | {{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= | ||
− | {{CGscriptParameters_Template|Type= | + | {{CGscriptParameters_Template|Type=int|Name=<nowiki>startIndex</nowiki>|Description=<nowiki>The position in this instance where the substring begins.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>length</nowiki>|Description=<nowiki>The length of the substring.</nowiki>}} |
|Description=<nowiki>Returns a substring in the string.</nowiki>}} | |Description=<nowiki>Returns a substring in the string.</nowiki>}} | ||
{{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=int|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|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}} |
}} | }} | ||
− | |||
=== Examples === | === Examples === | ||
+ | <source lang="javascript"> | ||
String s = "My name is: {0} {1} {2}"; | String s = "My name is: {0} {1} {2}"; | ||
String firstName = "Nam"; | String firstName = "Nam"; | ||
Line 44: | Line 46: | ||
sb.AppendFormat(s, firstName, middleName, lastName); | sb.AppendFormat(s, firstName, middleName, lastName); | ||
print(sb.ToString()); // Hello! My name is: Nam Van Nguyen | print(sb.ToString()); // Hello! My name is: Nam Van Nguyen | ||
+ | </source> |
Latest revision as of 09: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