Here is PHP's trim() function reproduced in Actionscript for use in a Flex application
public function trim(str:String):String
{
for(var i:Number = 0; str.charCodeAt(i) < 33; i++);
for(var j:Number = str.length-1; str.charCodeAt(j) < 33; j--);
return str.substring(i, j+1);
}
UPDATE: Thanks to Almog Kurtser, I now know that Flex has a utility to handle trimming strings. Here is an alternative example
import mx.utils.StringUtil;
public function trim(str:String):String
{
return StringUtil.trim(str);
}
Of course it is redundant to actually create a function called trim just to call the method StringUtil.trim() but you get the idea.