If you only need the season and year, then:
int firstSpace = text.IndexOf(' ');
string season = text.Substring(0, firstSpace);
int secondSpace = text.IndexOf(' ', firstSpace + 1);
int year = int.Parse(text.Substring(firstSpace + 1,
secondSpace - firstSpace - 1));
If you can assume the year is always four digits, this is even faster:
int firstSpace = text.IndexOf(' ');
string season = text.Substring(0, firstSpace);
int year = int.Parse(text.Substring(firstSpace + 1, 4));
If additionally you know that all years are in the 21st century, it can get stupidly optimal:
int firstSpace = text.IndexOf(' ');
string season = text.Substring(0, firstSpace);
int year = 2000 + 10 * (text[firstSpace + 3] - '0')
+ text[firstSpace + 4] - '0';
which becomes even less readable but possibly faster (depending on what the JIT does) as:
int firstSpace = text.IndexOf(' ');
string season = text.Substring(0, firstSpace);
int year = 1472 + 10 * text[firstSpace + 3] + text[firstSpace + 4];
Personally I think that's at least one step too far though :)
EDIT: Okay, taking this to extremes... you're only going to have a few seasons, right? Suppose they're "Spring", "Summer", "Fall", "Winter" then you can do:
string season;
int yearStart;
if (text[0] == 'S')
{
season = text[1] == 'p' ? "Spring" : "Summer";
yearStart = 7;
}
else if (text[0] == 'F')
{
season = "Fall";
yearStart = 5;
}
else
{
season = "Winter";
yearStart = 7;
}
int year = 1472 + 10 * text[yearStart + 2] + text[yearStart + 3];
This has the advantage that it will reuse the same string objects. Of course, it assumes that there's never anything wrong with the data...
Using Split
as shown in Spidey's answer is certainly simpler than any of this, but I suspect it'll be slightly slower. To be honest, I'd at least try that first... have you measured the simplest code and found that it's too slow? The difference is likely to be very slight - certainly compared with whatever network or disk access you've got reading in the data in the first place.