flexr

Parse Boolean method for Flex

with one comment

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);
}
}

Written by Jester theFool

August 12, 2008 at 11:59 pm

One Response

Subscribe to comments with RSS.

  1. 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.

    anon

    May 21, 2009 at 10:14 am


Leave a Reply