You can do the following
StringUtil.trim(string);
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html
String has a lot of methods which match for patterns you can find it here. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html