String split remove empty
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class Program { static void Main(string[] args) { string plants = "Golden Buttons,Goldenglow,,Goose Tongue,,,Groundberry"; Console.WriteLine(plants); //this line split string by comma and remove empty values and create string array. string[] splittedArray = plants.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //another option to split array and remove empty substring //string[] splittedArray = plants.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Console.WriteLine("\nstring splitted array elements......"); Array.ForEach(splittedArray, Console.WriteLine); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 |
Golden Buttons,Goldenglow,,Goose Tongue,,,Groundberry string splitted array elements...... Golden Buttons Goldenglow Goose Tongue Groundberry |