Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove blank values from array using C#

Tags:

c#

How can I remove blank values from an array?

For example:

string[] test={"1","","2","","3"}; 

in this case, is there any method available to remove blank values from the array using C#?

At the end, I want to get an array in this format:

test={"1","2","3"}; 

which means 2 values removed from the array and eventually I get 3.

like image 519
Mulesoft Developer Avatar asked Jan 11 '12 05:01

Mulesoft Developer


1 Answers

If you are using .NET 3.5+ you could use LINQ (Language INtegrated Query).

test = test.Where(x => !string.IsNullOrEmpty(x)).ToArray(); 
like image 61
Alex Avatar answered Oct 03 '22 21:10

Alex