How to split a string into an array by delimiter and remove empty elements in C#

1 Answer

0 votes
using System;

public class SplitStringIntoArrayByDelimiterRemoveEmptyElements_CSharp
{
	public static void Main(string[] args)
	{
		string s = "C#,Java,,C,,,Python,,,,,C++,,";

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

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



/*
run:

C#
Java
C
Python
C++

*/

 



answered Sep 23, 2024 by avibootz
...