C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Regex vs String.Split

Chapter 3: Parameterized typing with generics: 3.2.1

Created: 5/7/2008
Last updated: 5/7/2008

People who know my views on regular expressions and their misuse might be surprised to see me use one in listing 3.1. Surely String.Split is a great tool for splitting text into words? Well, yes and no. In particular, "no" when you can have several non-word characters in a row, and several different non-word characters - which is the case in the example. It's all feasible, of course, but in this case the regex was simpler.