Link to home
Start Free TrialLog in
Avatar of QuinnDester
QuinnDesterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

!string.IsNullOrEmpty c# Problem VS2010

In the code below i am trying to check that the string does not contain "" before processing.

some how this is still processing the string when it contains ""

the data is picked up from a comma delimited array, with blank ,,,,,, where there is no data, how can i stop the processing of stirngs that contain no data

Thank you
if (!string.IsNullOrEmpty(Charon))
                {
                    shipsRetrieved = shipsRetrieved + Charon + "<br />".ToString();
                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make a copy of the string, then remove all commas.  Now test if this string is empty.  (Remember to do this on a copy because it will trash the real line)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of QuinnDester

ASKER

the string is "" no commas in it, the data is collected from a comma delimted array, the ,,,,,, are just delimitations as place holders so the correct data is alway in the right place in the array.

i only mentioned this so you know how the data is picked up, incase that has a bearing on what is held in the string.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"" is an empty string.  As Divinity says that should be trapped and not processed.

Please paste your complete code - you might be missing something else and thinking the failure is with this bit of code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My mistake, i was checking for an empty string after adding additional text to the string, so they were never empty...

moving the check to earltier in the code sorted it out.