I had this problem when I used to work with VB and VBScript apps and was hoping that there would be a good way to deal with this, but I guess not.
When you have a string and you do not know whether it will be null or zero-length, you need to handle both. Well, what I've always done is:
if ( strValue+"" == "" )
...
I haven't ever heard anything for or against this method, but was wondering what the best route was. Does anyone have any suggestions? I've seen posts that mention a possible IsNullOrEmpty() method, which would solve the problem, but I'm not holding my breath.
I know that a possible solution is to use the Convert.ToString() method, but that is a bit long-winded for a simple boolean check; however, if you need to get a value and immediately perform some action on it, this is might be the best solution. For instance:
string[] ar_strValue = Convert.ToString(xyz).Split(';');
I still think this is a bit long-winded, but I can see why someone would use it as opposed to the appended zero-length string method.
Does anyone have any opinions about this?
[Edited 2/16/2004 9:30 AM]
One solution is to use a utility method (i.e. StringUtil.IsNullOrEmpty(string)). The problem with this is that +""=="" is 7 characters, while the previous method is 26. Which would you choose? Honestly.