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
Post a Comment