user3227070 user3227070 - 1 year ago 103
C# Question

C# splitting a string with multiple seperator

user1;user2;user3;user4 user1

I'd like to split these strings so I can iterate over all of them to put them in objects. I figured I could use


However, in the second example, there is no ; , so that wouldn't do the trick. What would be the best way to do this when it can be variable like this?


Answer Source

You can use overload taking multiple separators:

myString.Split(new[] { ";", " " }, StringSplitOptions.RemoveEmptyEntries);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download