How to split a string and remove empty elements from result in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str = "c#,, desktop,,, software, development";

        string[] arr = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

        foreach (string element in arr)
            Console.WriteLine(element.Trim());
    }
}




/*
run:

c#
desktop
software
development

*/

 



answered Oct 27, 2022 by avibootz
...