WMLScript » String » String.length

Syntax:
String.length(string)
string
The mandatory string parameter can be any string containing zero or more of any combination of characters (including white spaces). This parameter can also be an empty string.

Returns the length of the string.

The String.length function returns the integer length of a given string. If the string is an empty string, a zero is returned.

Note that you can use the String.isEmpty function to determine if a string is empty (i.e., has zero length).

Examples

Code:
<?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>
   length example
   </p>
   <do type="accept">
      <go href="LengthExample.wmls#findlength()" />
   </do>
</card>

<card id="card2">
<p>
   string = $(strng)
   <br />
   length = $(result)
</p>
</card>

</wml>
Explanation:

Code for LengthExample.wml

Language(s): WML
Code:
extern function findlength()
{
   var str = Dialogs.prompt("Enter a string", "");
   var len = String.length(str);
   WMLBrowser.setVar("strng", str);
   WMLBrowser.setVar("result", len);
   WMLBrowser.go("LengthExample.wml#card2");
};
Explanation:

Code for LengthExample.wmls

Language(s): WML

See Also: