A client upgraded their systems and they started to report bugs in the output. Apparently, a string split before resulted in the following.
"a-b-c" -> {"a", "b", "c"}
Now, however, they get this.
"a-b-c" -> {"a", "-", "b", "-", "c"}
I've checked intellisense but as far I can tell, there's no option for turning on/off the inclusion of separators. How can one tackle this easily?
The best suggestion I have off the top of my head is to split using regex and then where it using link with the matching condition of regex. Seems redundant, though...
The current version is 4.5. Before, they had something ooold, like 2.0 or something.
The behaviour of .NET 4.5 is correct.
The contents of capturing groups are added to the split result. Therefore, Regex.Split("a-b-c", "(-)");
will add the dashes to the array.
Use Regex.Split("a-b-c", "-");
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With