string
DescriptionThe string datatype represents a Unicode text value and provides a rich set of functions for querying, modifying, comparing, and converting textual data.
Most methods return a new string, except those explicitly modifying the internal value (insert, erase, replace).
Typical use cases
Processing user input.
Building dynamic messages and UI text.
String comparison and validation tasks.
Substring detection and extraction.
Converting numeric strings to int or float.
Notes
Strings are stored as Unicode.
Indexing is zero-based.
Methods do not throw exceptions; invalid ranges typically result in empty strings or no changes.
Case-conversion uses the system's locale and may not support full Unicode casing rules.
------------------------------------------------------------
Methods
------------------------------------------------------------
int length()
Returns the number of characters in the string.
------------------------------------------------------------
bool isEmpty()
Returns true if the string contains no characters.
------------------------------------------------------------
bool equals(string other)
Compares the string with another string using case-sensitive comparison.
------------------------------------------------------------
bool equalsIgnoreCase(string other)
Compares the string with another string ignoring case differences.
------------------------------------------------------------
int compareTo(string other)
Performs a lexicographical comparison similar to strcmp.
Returns 0 if equal, a negative value if this string is smaller, and a positive value if larger.
------------------------------------------------------------
int indexOf(string substring)
Returns the index of the first occurrence of the substring, or -1 if not found.
------------------------------------------------------------
int lastIndexOf(string substring)
Returns the index of the last occurrence of the substring, or -1 if not found.
------------------------------------------------------------
bool contains(string substring)
Returns true if the substring occurs anywhere in the string.
------------------------------------------------------------
bool startsWith(string prefix)
Checks whether the string begins with the specified prefix.
------------------------------------------------------------
bool endsWith(string suffix)
Checks whether the string ends with the specified suffix.
------------------------------------------------------------
string concat(string other)
Returns a new string combining this string and the provided argument.
------------------------------------------------------------
string substring(int start, int length)
Extracts a substring starting at the given index and spanning the specified length.
If the parameters exceed bounds, an empty string is returned.
------------------------------------------------------------
void insert(int pos, string text)
Inserts the given text at the specified character position.
Modifies the existing string.
------------------------------------------------------------
void replace(string target, string replacement)
Replaces all occurrences of target with replacement.
Modifies the existing string.
------------------------------------------------------------
void erase(int pos, int length)
Removes a section of the string beginning at the given position.
Modifies the existing string.
------------------------------------------------------------
string trim()
Returns a new string with leading and trailing whitespace removed.
------------------------------------------------------------
string toUpperCase()
Returns a new string converted to upper case.
Note: Only ASCII and locale-dependent casing is supported.
------------------------------------------------------------
string toLowerCase()
Returns a new string converted to lower case.
Note: Only ASCII and locale-dependent casing is supported.
------------------------------------------------------------
int toInt()
Converts the string to an integer.
If the contents are not numeric, an error is logged and 0 is returned.
------------------------------------------------------------
float toFloat()
Converts the string to a floating-point number.
If the contents are invalid, an error is logged and 0.0 is returned.
------------------------------------------------------------
Example
void main()
{
string a = "Hello";
string b = "World";
string c = a.concat(" ").concat(b);
Print("Result: " + c);
if (c.contains("World"))
Print("Substring found");
}