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"?>

<card id="card1">
   elements example
   <do type="accept">
      <go href="ElementsExample.wmls#findelements()" />

<card id="card2">
   string = $(strng)
   <br />
   separator = $(separator)
   <br />
   # of elements = $(numelements)


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);

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