views:

86

answers:

1

Possible Duplicate:
C#: Convert string to model

Let's say I need to take a string and turn it into an array. This string has a single universal character to denote a new element. For example, I want to turn this string:

var s = "first|second|third";

Into this array:

var segments = new[]
{
    "first",
    "second",
    "third"
};

Is there an easier way to do it than this:

var segments = s.Split(new char[] { '|' });

I feel uncomfortable writing (new char[] { '|' }. I feel like there's probably this method, but I can't find its signature:

var segments = s.Split('|');
+1  A: 

The answer is exactly what you just wrote!

var s = "first|second|third";
var segments = s.Split('|');
SamStephens
Yeah, I was just about to write the EXACT same thing...
Alastair Pitts