Tuesday, 27 October 2009 15:55
I found this snippet while revisiting some old code, and thought it might help someone else. It's trim() for AS3, and it should work in Flash or Flex.
function trim( s:String ):String { return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" ); }
Last Updated on Thursday, 29 October 2009 15:14
Comments (8)
Add your comment
Featured Extensions
|
$5.00
|
FREE
|
$1.00
FREE You Save: $1.00 |
$3.00
|





Yours is short and doesn't use an extra function call, but does it also strip newlines and tabs?
Also, looking now at the PHP manual for trim, it seems I missed NUL and vertical tab: http://php.net/manual/en/function.trim.php
The \s matches any white-space character (a space, tab, newline, or return character).
http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000112.html
function trim(s:String):String {
return s ? s.replace(/^\s+|\s+$/gs, '') : "";
}