WMLScript » String » String.trim

Syntax:
String.trim(string)
string
The mandatory string 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.

Removes all leading and ending white space in a string.

The String.trim function takes the given string and removes all of the leading and trailing white spaces (if any). No white space inside the string (between the characters and elements) is removed. This function returns the modified string.

You can use the String.squeeze function to remove extra white spaces between the 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>
   trim example
   </p>
   <do type="accept">
      <go href="TrimExample.wmls#findtrim()" />
   </do>
</card>

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

</wml>
Explanation:

Code for TrimExample.wml

Language(s): WML
Code:
extern function findtrim()
{
   var str = Dialogs.prompt("Enter a string", "");
   var trimstr = String.trim(str);
   WMLBrowser.setVar("strng", str);
   WMLBrowser.setVar("trimstrng", trimstr);
   WMLBrowser.go("TrimExample.wml#card2");
};
Explanation:

Code for TrimExample.wmls

Language(s): WML

See Also: