Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 607
Hassan Mokdad Avatar asked Feb 18 '12 10:02

Hassan Mokdad


2 Answers

The following will catch all of these:

  1. NULL
  2. empty string
  3. whitespace only string

import mx.utils.StringUtil;

var str:String

if(!StringUtil.trim(str)){
   ...
}
like image 106
Davem M Avatar answered Sep 23 '22 02:09

Davem M


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

like image 28
Richard Walton Avatar answered Sep 23 '22 02:09

Richard Walton