C# – Getting rid of null/empty string values in a C# array


I have a program where an array gets its data using string.Split(char[] delimiter).
(using ';' as delimiter.)

Some of the values, though, are null. I.e. the string has parts where there is no data so it does something like this:

1 ;2 ; ; 3;

This leads to my array having null values.

How do I get rid of them?

Best Answer

Try this:

yourString.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries);