Return to Snippet

Revision: 26768
at May 10, 2010 09:55 by adrianparr


Initial Code
function trimWhitespace($string:String):String {
	if ($string == null) {
		return "";
	}
	return $string.replace(/^\s+|\s+$/g, "");
}

var myString:String = "           Hello World               ";
trace(trimWhitespace(myString));
// OUTPUT
// Hello World

Initial URL

                                

Initial Description

                                

Initial Title
AS3 Trim Whitespace From the Beginning and End of a String

Initial Tags
regex, replace, regexp

Initial Language
ActionScript 3