Wednesday, April 20, 2011

string.Split

There is no question that, compared to C++, C# makes working with strings a lot easier. However, some things still don't make sense. I have used the split method on the string class countless times. I could count on one hand the number of times I had more than one argument to split by. Why is there no overload that takes a single string or char, and doesn't force me to write code that creates a single element array inline so I can satisfy the method signature requirements ?

4 comments:

  1. To encourage noobs to write their first extension method.

    PS I hope your wife's doing better.

    ReplyDelete
  2. Thanks - she is doing a lot better. Good answer :P

    ReplyDelete
  3. What's wrong with

    "Split me into words!".Split(' ', StringSplitOptions.RemoveEmptyEntries);

    ???

    ReplyDelete