Splitting a string based on multiple char delimiters in C#
To split string on multiple delimiters in C# we use methodSplit(new Char [] {param1, param2, param3, ...})
which can take a list of delimiters.Example
using System;
using System.Linq;
public class Example
{
public static void Main()
{
string strings = "hello World\n how, are you";
string [] split = strings .Split(new Char [] {',' , '\n' , ' ' });
split.ToList().ForEach(i => Console.WriteLine(i.ToString()));
}
}
Output
hello
World
how
are
you
World
how
are
you