String
The String object is used to represent a series of characters.
Syntax
The syntax for this object is:
new String(str)//Or
"string"
Where:
str represents the value to store in the String object.
Sample
<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC "-//Nuance/DTD VoiceXML 2.0//EN"
"http://voicexml.nuance.com/dtd/nuancevoicexml-2-0.dtd" >
<vxml version="2.0">
...
<script>
var prompt;
/*Creating an instance of a String object and
assigning the name "AMEX" to it.*/
var account= new String("AMEX");/*Searching for "AMEX" and using the String object’s replace() method to replace it by "VISA".*/
var myRegExp = /AMEX/;
var newAccount = account.replace(myRegExp, "VISA");
prompt = "The system has updated your account information. From now on, all payments will automatically be charged to your " + newAccount;
</script>
...
</vxml>
Properties
This section describes the String object properties.
The constructor property identifies the function used to create the String object’s prototype
The syntax for this property is:
string.constructor
The length property specifies the number of characters in a string.
The syntax for this property is:
string.length
The prototype property is used to add new methods and properties to the String object.
The syntax for this property is:
string.prototype.methodstring.prototype.property
Methods
This section describes the String object methods.
The charAt method extracts the character located at the indexed position from a string.
The syntax for this method is:
string.charAt(character_index)
The charCodeAt method returns the Unicode encoding of the character located at the indexed position in a string.
The syntax for this method is:
string.charCodeAt(character_index)
The concat method concatenates two strings.
The syntax for this method is:
string.concat(stringB, ...)
The fromCharCode method allows you to create a string by specifying the numeric Unicode encodings of its characters.
The syntax for this method is:
String.fromCharCode(num1, num2, ...)
Where:
num1, num2, ... are the numeric Unicode encoding of the characters.
The indexOf method searches the String object from beginning to end for the first occurrence of the specified character or substring.
The syntax for this method is:
string.indexOf(substring)
string.indexof(substring, begin)
The lastIndexOf method searches the String object from end to beginning for the first occurrence of the specified character or substring.
The syntax for this method is:
string.lasrIndexOf(substring)
string.lastIndexof(substring, begin)
The localeCompare method compares one string to another using the locale-specific ordering provided by the underlying operating system.
The syntax for this method is:
string.localeCompare(stringX)
Where:
stringX represents the string you want to compare.
The match method searches the String object for one or more regular expression matches.
The syntax for this method is:
string.match(regExpression)
The replace method searches a string for a substring that matches a regular expression and replaces it by another string or function.
The syntax for this method is:
string.replace(regExpression, replacementString)
The search method searches a string for a substring that matches a regular expression.
The syntax for this method is:
string.search(regExpression)
The slice method returns a substring of a string.
The syntax for this method is:
string.slice(index1, index2)
Where:
index1 is a string index that specifies where to begin the slice.
index2 is the string index that immediately follows the end of the slice.
The split method splits a string into an array of strings.
The syntax for this method is:
string.split(delimiter, max)
Where:
delimiter represents the string or regular expression where the string splits.
max specifies the maximum length of the array that is returned.
The substring method extracts a substring from a string.
The syntax for this method is:
string.substring(index1, index2)
Where:
index1 is the position of the first character to extract from the string.
index2 is one greater than the position of the last character to extract from the string.
The toLocaleLowerCase method converts all characters in a string to lowercase according to the operating system’s current locale.
The syntax for this method is:
string.toLocaleLowerCase()
The toLocaleUpperCase method Converts all characters in a string to uppercase according to the operating system’s current locale.
The syntax for this method is:
string.toLocaleUpperCase()
The toLowerCase method converts all characters in a string to lowercase.
The syntax for this method is:
string.toLowerCase()
The toSource method returns a string representation of the string passed.
The syntax for this method is:
string.toSource()
The toString method returns the primitive string value of the String object.
The syntax for this method is:
string.toString()
The toUpperCase method converts all characters in a string to uppercase.
The syntax for this method is:
string.toUpperCase()
The valueOf method returns the primitive string value of the String object.
The syntax for this method is:
string.valueOf()