Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split String at position in C#

I have a date stamp (020920111422) and I want to split it to

day = 02, month = 09, year = 2011, hour = 14, and minute = 22

Is there a "split string at position" method in C#?

like image 262
hogni89 Avatar asked Sep 12 '11 10:09

hogni89


1 Answers

You want:

string x = s.Substring(0, i), y = s.Substring(i);

(or maybe i-1/i+1 depending on your exact requirements).

However, you could also use DateTime.ParseExact to load it into a DateTime by telling it the explicit format:

var when = DateTime.ParseExact("020920111422", "ddMMyyyyHHmm",
    CultureInfo.InvariantCulture);
like image 161
Marc Gravell Avatar answered Sep 28 '22 05:09

Marc Gravell