WMLScript elementAt() function
The elementAt() function divides the string into elements and returns the element at the specified index.
Syntax
n = String.elementAt(string, index, separator)
Component | Description |
---|---|
n | The string returned from the function. |
string | The string to be parsed. |
index | An integer, defining the part returned. |
separator | Separator used to separate strings. |
Note:If index is negative, it returns the first element. If the value of index is too large, it returns the last element.
Example
var a= String.elementAt("Visit CodeW3C.com today",0," "); var b= String.elementAt("Visit CodeW3C.com today",1," "); var c= String.elementAt("Visit CodeW3C.com today",2," "); var d= String.elementAt("Apples+Bananas",0,"+"); var e= String.elementAt("Apples+Bananas",1,"+"); var f= String.elementAt("Apples+Bananas",5,"+");
Result
a = "Visit" b = "W3School" c = "today" d = "Apples" e = "Bananas" f = "Bananas"