I’m trying to split a string that can either be comma, space or semi-colon delimitted. It could also contain a space or spaces after each delimitter. For example
22222,11111,23232
OR
22222, 11111, 23232
OR
22222; 11111; 23232
OR
22222 11111 23232
Any one of these would produce an array with three values ["22222","11111","23232"]
So far I have var values = Regex.Split("22222, 11111, 23232", @"[\\s,;]+") but this produces an array with the second and third values including the space(s) like so:
["22222"," 11111"," 23232"]
You have two possibilities:
Regex.SplitString.SplitIn this case, you want to split your string by specific delimiters caracters.
String.Splithas been created for this special purpose. This method will be faster thanRegex.Split.