.NET 2.0 makes this kind of comparison very easy. There is a new static
method on the String class called "IsNullOrEmpty" which returns true if the
string passed to it is null or empty.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Marcos Stefanakopolus" <ta*******@hotmail.com> wrote in message
news:42********@news.microsoft.com...
Or, as may be more helpful depending on the types of conditions you're
trying to catch:
if(x[i] == null || x[i] == String.Empty)
"Denny Britz" <zo***@web.de> wrote in message
news:ei****************@TK2MSFTNGP14.phx.gbl... Hi,
I have an array of of 5 string elements. I put values in 3 of them.
Yet
when I loop over them, I do not catch the empty string. The code output
below does not include "Empty"
Your string equals String.Empty when its value is "".
In your code sample, your string doesn't have any value,
so you have to compare it with null:
if(x[i]==null)
{
msg+=msg+"Empty\n";
}
---------------------------
string[]x=new String[5];
x[0]="111";
x[1]="222";
x[2]="333";
x[3]="";
x[4]="";
string msg="";
for(int i=0;i<x.Length;i++)
{
if(x[i]==String.Empty)
{
msg+=msg+"Empty\n";
}
else
{
msg=msg+x[i]+"\n";
}
}
MessageBox.Show(msg);