String.Append(string str2)Appends the string STR2 to the end of the specified string, and returns the result.
IMPORTANT: The result of joining the strings together is returned as a new
string from this command. The original string will NOT be changed. For
example, the following script will not do anything:
mytext.Append("World");
what you probably want instead is:
mytext = mytext.Append("World");
Example:
String mytext = "Hello";
mytext = mytext.Append("World");
Display(mytext);
will display "HelloWorld".See Also: String.AppendChar, String.Substring, String.Truncate
String.AppendChar(char extraChar)Appends a single character to the end of the specified string, and returns the result.
IMPORTANT: The newly extended text is returned as a new string from this command.
The original string will NOT be changed. For
example, the following script will not do anything:
mytext.AppendChar('o');
what you probably want instead is:
mytext = mytext.AppendChar('o');
Example:
String mytext = "Hell";
mytext = mytext.AppendChar('o');
Display(mytext);
will display "Hello".See Also: String.Append
String.CompareTo(string str2, optional bool caseSensitive)Compares the specified string to STR2. caseSensitive determines whether "Dog" and "dog" are equivalent; case sensitivity is off by default.
Returns 0 if the strings match, a number less than 0 if this string is earlier in the alphabet than STR2, and a number greater than 0 if this string is later in the alphabet than STR2.
TIP: To do a case-sensitive comparison of two strings, it's easier to just use the == operator.
Example:
String mytext = "Hello";
if (mytext.CompareTo("hello") == 0) {
Display("Strings match with case sensitivity off!");
}
else {
Display("Strings don't match with case sensitivity off!");
}
if (mytext == "hello") {
Display("Strings match with case sensitivity on!");
}
else {
Display("Strings don't match with case sensitivity on!");
}
will display "Strings match with case sensitivity off!", and then "Strings don't match with case sensitivity on!".
String.Contains(string needle)Checks to see if NEEDLE is contained within the specified string. Returns the character position of the match if it is, or -1 if it is not.
This function is not case sensitive; ie. testing "test string" for "sTRiN" would match.
Example:
String haystack = "The haystack had a needle in it somewhere.";
int result = haystack.Contains("a needle");
if (result == -1) {
Display("The string didn't contain the needle.");
}
else {
Display("a needle was found starting at character %d in the string.", result);
}
String.Copy()Returns a new copy of the specified string. You should not normally need to use this, since strings can be assigned using the = operator.
Example:
String mystring = "This is a test string."; String newstring = mystring.Copy(); Display(newstring);will display "This is a test string".
static String.Format(string fmt, ...)Processes the string FMT in the same way as the Display function does but instead of displaying it on the screen, returns the result as a new string.
You can insert the value of variables into the message. For more information, see the string formatting section.
NOTE: This function is static, which means you do not call it on an existing string variable, but use String.Format() instead.
Example:
int health=10;
String text = String.Format("%d", health);
will create a text string containing "10".See Also: Display
String.LowerCase()Returns a lower case version of the specified string.
NOTE: The new string is returned from this function; it does NOT modify the original string.
Example:
String mystring = "THIS is a test string";
String lowercased = mystring.LowerCase();
Display("Old: %s, new: %s", mystring, lowercased);
will display "Old: THIS is a test string, new: this is a test string".See Also: String.UpperCase
String.ReplaceCharAt(int index, char newChar)Changes the character at INDEX in the string to NEWCHAR.
INDEX is the character index into the string (where 0 is the first character, and the last allowable value is the string's Length minus 1).
NOTE: The new string is returned from this function; it does NOT modify the original string.
Example:
String mystring = "Hello";
String changed = mystring.ReplaceCharAt(2, 'm');
Display("Old: %s, new: %s", newstring, changed);
will display "Old: Hello, new: Hemlo".See Also: String.Chars
String.Substring(int index, int length)Returns part of the string, starting from character index and length characters long.
index is the initial character index, where 0 is the first character and (Length - 1) is the last. length specifies how many characters to retrieve.
Example:
String mystring = "Hello World!";
String substring = mystring.Substring(3, 5);
Display("Original: %s, Substring: %s", mystring, substring);
will display "Original: Hello World!, Substring: lo Wo".See Also: String.Append, String.Chars
String.Truncate(int length)Returns a version of the string that has been truncated down to length characters.
NOTE: The new string is returned from this function; it does NOT modify the original string.
Example:
String mystring = "Hello World!";
String truncated = mystring.Truncate(4);
Display("Original: %s, Truncated: %s", mystring, truncated);
will display "Original: Hello World!, Truncated: Hell".See Also: String.Append, String.Substring
String.UpperCase()Returns an upper case version of the specified string.
NOTE: The new string is returned from this function; it does NOT modify the original string.
Example:
String mystring = "THIS is a test string";
String uppercased = mystring.UpperCase();
Display("Old: %s, new: %s", mystring, uppercased);
will display "Old: THIS is a test string, new: THIS IS A TEST STRING".See Also: String.LowerCase
readonly float String.AsFloat;Converts the string into a float, and returns that value. Returns 0.0 if the string does not contain a number.
Example:
String text1, text2; float number1,number2; text1 = "57.362"; text2 = "Hello"; number1 = text1.AsFloat; number2 = text2.AsFloat;will set number1 value to 57.362 and number2 value to 0.0 This function is useful for processing strings input from the user.
NOTE: To convert a float to a string, you can use the String.Format command.
See Also: Game.InputBox, String.AsInt, String.Format
readonly int String.AsInt;Converts the string into an integer, and returns that value. Returns zero if the string does not contain a number.
Example:
String text1, text2; int number1,number2; text1 = "53"; text2 = "Hello"; number1 = text1.AsInt; number2 = text2.AsInt;will set number1 value to 53 and number2 value to 0. This function is useful for processing strings input from the user.
NOTE: To convert an integer to a string, you can use the String.Format command.
See Also: Game.InputBox, String.AsFloat, String.Format
readonly char String.Chars[position];Returns the character at POSITION within the string.
POSITION is the character index (where 0 is the first character, and the last allowable value is the Length minus 1).
If POSITION is outside the string, this function returns 0.
NOTE: The Chars array is read-only. If you want to change one of the characters in the string, use String.ReplaceCharAt.
Example:
String text = "This is my string.";
Display("The 4th character is: %c", text.Chars[3]);
will display "The 4th character is: s".See Also: String.Length, String.ReplaceCharAt
readonly int String.Length;Returns the length of the string, in characters.
Example:
String text = "This is my string.";
Display("Length: %d", text.Length);
will display "Length: 18".