c# - Replacing characters at specific locations -



c# - Replacing characters at specific locations -

my input string represent machine's execution time , date. problem string formatted badly hence can't utilize datetime.parse convert datetime object. input example:

2014-01-07-15.26.46.000452

i need convert can work (replacing lastly '-' space , first 2 '.' ':') so:

2014-01-07 15:26:46.000452

i figured should utilize regex solve because need replace characters @ specific locations mystring.replace won't good. unfortunately, knowledge of using regex close nil , couldn't find examples match problem. can help me solve 1 out? (also, explanation on how & why regex works)

it doesn't pretty, job:

string yourstring = "2014-01-07-15.26.46.000452"; string newstring = regex.replace(yourstring, @"(\d+)-(\d+)-(\d+)-(\d+).(\d+).(\d+).(\d+)", "$1-$2-$3 $4:$5:$6.$7");

it cuts numerics apart gibberish around , constructs date want to.

c# regex string

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -