FUNCTION:  String.elements

String.elements(string, index, separator)
 
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).
 
The mandatory string parameter can be any string containing zero or more of any combination of characters and white spaces. The empty string "" is usually recognized as one element.
 
The mandatory separator parameter can be one or more characters, including one or more of any type of white space characters, that you wish to use to divide the string into substrings called elements. (Depending on the browser, if the separator is set to be the empty string, either invalid or 1 will be returned.)
 
Code for ElementsExample.wml
<?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.wmls
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");
};


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information