The String Library contains sixteen functions that can be used to manipulate a string.
By definition, a string is an array of characters. The length of a string (size of the array) is the total number of characters in the array, including white space. Each character in the string has an index position, where the first character is at position zero. A string can also be composed of a series of elements that are delineated by separators. A separator can be any character. Certainly, the most commonly used separator is a blank space, which is one of six types of white space recognized by WMLScript.
The six types of white space are:
Character | Description |
---|---|
CR | Carriage Return |
FF | Form Feed |
LF | Line Feed |
SP | Blank Space |
TAB | Horizontal tab |
VT | Vertical Tab |
Syntax: String.charAt(string, index)
Returns the character at the specified location in the string.
Syntax: String.compare(string1, string2)
Compares and ranks two strings.
Syntax: String.elementAt(string, index, separator)
Returns the specified portion of a string.
Syntax: String.elements(string, separator)
Returns the number of occurrences of a specified character element.
Syntax: String.find(string, substring)
Returns the location of a specified substring in a string.
Syntax: String.format(format, value)
Converts a given value to a string using a specified format.
Syntax: String.insertAt(string, element, index, separator)
Inserts an element and separator into a string.
Syntax: String.isEmpty(string)
Determines if a string is empty.
Syntax: String.length(string)
Returns the length of the string.
Syntax: String.removeAt(string, index, separator)
Remove a specified substring from a string.
Syntax: String.replace(string, oldSubString, newSubString)
Replaces all occurrences of a substring with a new substring.
Syntax: String.replaceAt(string, element, index, separator)
Replaces a specified occurrence of a substring with a new substring.
Syntax: String.squeeze(string)
Removes extra white space.
Syntax: String.subString(string, startIndex, length)
Creates a new string by selecting a substring out of an existing string.
Syntax: String.toString(value)
Converts a given value to a string.
Syntax: String.trim(string)
Removes all leading and ending white space in a string.