Remove White spaces from string in flash – Actionscript 3 (AS3)
This examples shows how to remove white spaces from the string
public function removeSpaces(str:String):String {
if (str == null) { return ''; }
return str.replace(/\s+/g, '');
}
This is the complete flex example
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
public function removeSpaces(str:String):String {
if (str == null) { return ''; }
return str.replace(/\s+/g, '');
}
public function on_trim_button():void {
reultText.text = removeSpaces(originalText.text);
}
]]>
</mx:Script>
<mx:Button x="74" y="101" label="Trim Spaces" click="on_trim_button()"/>
<mx:TextArea x="74" y="42" id="originalText" />
<mx:TextArea x="74" y="157" id="reultText" />
<mx:Label x="74" y="16" text="Enter Text" width="160"/>
<mx:Label x="74" y="131" text="Enter Text" width="160"/>
</mx:Application>