WMLScript » String » String.toString

Syntax:
String.toString(value)
value
The mandatory value parameter can be any combination of zero or more characters (letters, numbers, decimal points, etc.) and white spaces. If the value is an empty string, an empty string is returned.

Converts a given value to a string.

The String.toString function takes the given value and converts it into a string. The value can be a boolean, fixed-point number, floating-point number, or even a string. The converted value is returned. If the value is invalid, then this function returns invalid.

Once the value is converted, you can use the String.trim function to remove all leading and trailing white space. You can also use the String.squeeze to remove extra white spaces between characters and elements.

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>
   toString example
   </p>
   <do type="accept">
      <go href="ToStringExample.wmls#findtostring()" />
   </do>
</card>

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

</wml>
Explanation:

Code for ToStringExample.wml

Language(s): WML
Code:
extern function findtostring()
{
   var val = Dialogs.prompt("Enter a value", "");
   var str = String.toString(val);
   WMLBrowser.setVar("strng", str);
   WMLBrowser.setVar("value", val);
   WMLBrowser.go("ToStringExample.wml#card2");
};
Explanation:

Code for ToStringExample.wmls

Language(s): WML

See Also: