WMLScript » Functions » String

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


The library and function names are case sensitive.

String.charAt

Syntax: String.charAt(string, index)

Returns the character at the specified location in the string.

String.compare

Syntax: String.compare(string1, string2)

Compares and ranks two strings.

String.elementAt

Syntax: String.elementAt(string, index, separator)

Returns the specified portion of a string.

String.elements

Syntax: String.elements(string, separator)

Returns the number of occurrences of a specified character element.

String.find

Syntax: String.find(string, substring)

Returns the location of a specified substring in a string.

String.format

Syntax: String.format(format, value)

Converts a given value to a string using a specified format.

String.insertAt

Syntax: String.insertAt(string, element, index, separator)

Inserts an element and separator into a string.

String.isEmpty

Syntax: String.isEmpty(string)

Determines if a string is empty.

String.length

Syntax: String.length(string)

Returns the length of the string.

String.removeAt

Syntax: String.removeAt(string, index, separator)

Remove a specified substring from a string.

String.replace

Syntax: String.replace(string, oldSubString, newSubString)

Replaces all occurrences of a substring with a new substring.

String.replaceAt

Syntax: String.replaceAt(string, element, index, separator)

Replaces a specified occurrence of a substring with a new substring.

String.squeeze

Syntax: String.squeeze(string)

Removes extra white space.

String.subString

Syntax: String.subString(string, startIndex, length)

Creates a new string by selecting a substring out of an existing string.

String.toString

Syntax: String.toString(value)

Converts a given value to a string.

String.trim

Syntax: String.trim(string)

Removes all leading and ending white space in a string.

See Also: