Check if a string is empty in action script, similar to String.Empty in .net

Hassan Mokdad picture Hassan Mokdad · Feb 18, 2012 · Viewed 16.5k times · Source

Is there a static property in Action similar to that in the String object in .net to check if a string is empty, that is String.Empty.

Thanks

Answer

Richard Walton picture Richard Walton · Feb 18, 2012

You can simply do:

if(string) 
{
    // String isn't null and has a length > 0
}
else
{
   // String is null or has a 0 length
}

This works because the string is coerced to a boolean value using these rules:

String -> Boolean = "false if the value is null or the empty string ( "" ); true otherwise."