I Z I Z - 1 year ago 78
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
? Or is there a better way of splitting using my custom delimiter set + whitespaces? Thx

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download