Flex Pasta » Actionscript String Util Class

Actionscript String Util Class

Simple string manipulation is done on a daily basis in any language including flex. By using utility classes, you can reduce simple code errors and increase readability. I find the mx.utils.StringUtil could use a little more muscle than the 4 methods given out of the box. Downloadable is my own StringUtil class that beefs up the support for common string functions. The additions are based on the methods found in Apache Commons Lang open source code that includes a popular org.apache.commons.lang.StringUtils class.

Here is a summary of some of the methods you will find:

isEmpty : Checks if a String is empty (”") or null.
isNotEmpty : Checks if a String is empty (”") or null.
isBlank : Checks if a String is whitespace, empty (”") or null.
isNotBlank : Checks if a String is not whitespace, empty (”") or null.
defaultIfEmpty : Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

If you have a String Utility method for flex/actionscript, post it!

Download com.flexpasta.utils.StringUtil

3 Comments

  • 1. JabbyPanda replies at 24th March 2009, 2:48 pm :

    If you will cast your String to Boolean, for example by using comparasion like:

    if (myString) {
    trace (”do something”)
    }

    then you do not need to use extra methods from your StringUtil class like isEmpty and isNotEmpty

    See http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f87.html article “Casting to boolean” section.

  • 2. Brian Telintelo replies at 21st April 2009, 6:04 pm :

    Great point. However, I disagree with using that syntax. I don’t like having the execution of logic depend on a variable type or the expansion of null to include “”.

  • 3. Igor replies at 12th November 2010, 6:58 am :

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Apache/1.3.33 Server at http://www.flexpasta.com Port 80

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>