Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Collapse Whitespace function for Actionscript (See related posts)

This function will strip out all tabs and return characters. It will also collapse all runs of multiple spaces down to one. It will also remove a leading and trailing spaces. It is similar to the php_strip_whiespace() function in PHP.

function collapseWhiteSpace( theString ) {
        theString =  theString.split("\r").join("");
        theString =  theString.split("\t").join("");
        while ( theString.indexOf("  " ) != -1 ) {
                theString= theString.split("  ").join(" ");
        }
        if (theString.substr(0,1) == " ") {
                theString = theString.substr( 1 );
        }
        if (theString.substr( theString.length-1, 1 ) == " ") {
                theString = theString.substr( 0, theString.length - 1 );
        }
        return( theString );
}

You need to create an account or log in to post comments to this site.


Related Posts