I Z I Z - 1 month ago 7
C# Question

c#: how to split string using default whitespaces + set of addtional delimiters?

I need to split a string in C# using a set of delimiter characters. This set should include the default whitespaces (i.e. what you effectively get when you

String.Split(null, StringSplitOptions.RemoveEmptyEntries)
) plus some additional characters that I specify like '.', ',', ';', etc. So if I have a char array of those additional characters, how to I add all the default whitespaces to it, in order to then feed that expanded array to
String.Split
? Or is there a better way of splitting using my custom delimiter set + whitespaces? Thx

Answer

Just use the appropriate overload of string.Split if you're at least on .NET 2.0:

char[] separator = new[] { ' ', '.', ',', ';' };
string[] parts = text.Split(separator, StringSplitOptions.RemoveEmptyEntries);