WMLScript » String » String.squeeze

Syntax:
String.squeeze(string)
string
The mandatory string parameter can be any string containing one or more of any combination of characters and white spaces.

Removes extra white space.

The String.squeeze function removes all extra white spaces out of a given string. All occurrences of consecutive white space characters are reduced down to one white space character. The modified string is returned.

You can use the String.trim function to remove all leading and trailing white spaces in a string.

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

<card id="card2">
<p>
   old string = $(oldstrng)
   <br />
   new string = $(newstrng)
</p>
</card>

</wml>
Explanation:

Code for SqueezeExample.wml

Language(s): WML
Code:
extern function findsqueeze()
{
   var oldstr = Dialogs.prompt("Enter a string", "");
   var newstr = String.squeeze(oldstr);
   WMLBrowser.setVar("oldstrng", oldstr);
   WMLBrowser.setVar("newstrng", newstr);
   WMLBrowser.go("SqueezeExample.wml#card2");
};
Explanation:

Code for SqueezeExample.wmls

Language(s): WML

See Also: