Welcome! and rules
Joel on Software
Split() is opposite of Join()? Not!
In VB6 this was easy:
By using Regex.Split instead. There's no other way, unless you want to manually traverse the input string and look for occurrences of the splitter string. Here's how it works (in C#):
Duh, there are static methods that make it even simpler... just use this:
Thanks! A little hard to find, but this is as easy as it gets in C#. I suspected I needed RegEx, but I never got the hang of it so I never thought it would be this easy.
Well, you could just add a reference to Microsoft.VisualBasic and use the VB library. Works fine.
Maybe, but it's a dirty hack for fixing a stupid inconsistency: Join() uses a string, Split() a char. Hello C# team, time to do a code review?
I imagine the Framework team would have more interest in something like this than the C# team. Besides, an array of char make perfect sense for Split because that's exactly how it uses that parameter -- it looks for *each* char in the array, not for the full string.
Perfect sense when that is what you need, and sometimes it is. But they could bother to overload it whith a string parameter so it would work just as the opposite of Join().
I think there would be globalisation issues with having String.Split taking strings -- so Regex.Split would be the way to go. Granted, a pointer in the docs would be helpful.
just anoter (dirty) way to do it
Except that that will also kill any | that happen to be in the target string.
Brad Wilson (dotnetguy.techieswithcats.com)
Fog Creek Home