Skip to content

Parse Boolean method for Flex

August 12, 2008

I wonder why there isn’t an out of the box Boolean parser in Flex, I must have built this same method at least 3 times for different projects… You should probably add this to your utils as well.

static public function parseBoolean(str:String):Boolean {
switch(str) {
case "1":
case "true":
case "yes":
return true;
case "0":
case "false":
case "no":
return false;
default:
return Boolean(str);
}
}

From → Uncategorized

2 Comments
  1. anon permalink

    You might want to do a String.toLowerCase() before you start switching.

    Also, using enumerations will avoid a lot of headache whenever you’ve the luxury of being able to use them.

  2. Dan permalink

    It’s not rocket science but it saved me a few minutes of work.

    Cheers mate 😉

Leave a comment