Returns the number of occurrences of a specified character element.
The
String.elements function determines and then returns the number
of elements (substrings) that are separated by the given separator and
are contained in the specified string.
This
function treats a string as an array composed of elements delimited by
a separator that is composed of one or more specified characters
(including white space).
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
elements
example
</p>
<do type="accept">
<go
href="ElementsExample.wmls#findelements()" />
</do>
</card>
<card id="card2">
<p>
string = $(strng)
<br />
separator = $(separator)
<br />
# of
elements = $(numelements)
</p>
</card>
</wml>
Code for ElementsExample.wml
extern function findelements()
{
var str = Dialogs.prompt("Enter a string", "Hello
wireless world!");
var sep =
Dialogs.prompt("Enter a separator", " ");
var numelem = String.elements(str, sep);
WMLBrowser.setVar("strng", str);
WMLBrowser.setVar("separator", sep);
WMLBrowser.setVar("numelements", numelem);
WMLBrowser.go("ElementsExample.wml#card2");
};
Code for ElementsExample.wmls