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.
Hi,actually Flex has a built in function to trim strings in the StringUtil class.
ReplyDeletehttp://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trim-method/
Cheers,
Almog Kurtser
@Almog
ReplyDeleteAh, Thanks for the tip. I was not aware of the StringUtil class or it's methods. I will update my post.
It's a well camouflaged class indeed!
ReplyDeleteI noticed it only when I had to trace down an i18n bug on the ResourceManager.
btw, nice implementation, in the flex version, they implement it with a switch statement to check whether a character is a whitespace.