user3227070 user3227070 - 9 months ago 51
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?



You can use overload taking multiple separators:

myString.Split(new[] { ";", " " }, StringSplitOptions.RemoveEmptyEntries);