日期:2014-05-18 浏览次数:21123 次
string inputStr = @" 1 12 3 17 22 0 0.0 1.500000000000D+01 2 12 3 18 4 0 0.0 6.500000000000D+01 13 12 3 18 12 0 0.0 4.300000000000D+01 4 09 12 12 4 0 0.0 7.400000000000D+01 5 12 12 3 6 0 0.0 2.600000000000D+01 6 12 3 18 11 59 44.0 0.000000000000D+00 37 12 3 18 2 0 0.0 4.700000000000D+01 28 12 3 18 4 0 0.0 4.900000000000D+01 9 11 9 3 10 0 0.0 3.600000000000D+01 10 12 3 18 4 0 0.0 7.200000000000D+01 11 12 3 17 22 0 0.0 5.700000000000D+01 12 12 3 22 10 0 0.0 8.000000000000D+01 33 12 3 18 12 0 0.0 3.200000000000D+01 14 12 3 18 12 0 0.0 6.300000000000D+01 45 12 3 18 8 0 0.0 4.300000000000D+01 16 12 3 19 11 59 44.0 5.000000000000D+00 " ; Regex reg = new Regex(@"(\d{2} \d{1,2} \d{1,2})( \d{1,2} \d{1,2} \d{1,2}\.\d)"); DateTime firstDate = Convert.ToDateTime(reg.Match(inputStr).Groups[1].Value); DateTime baseDate = new DateTime(2011, 1, 1); TimeSpan ts = firstDate - baseDate; string outputStr = reg.Replace(inputStr, new MatchEvaluator((m) => { return (Convert.ToDateTime(m.Groups[1].Value) - ts).ToString("yy M d") + m.Groups[2].Value; })); Console.WriteLine(outputStr); /* 1 11 1 1 22 0 0.0 1.500000000000D+01 2 11 1 2 4 0 0.0 6.500000000000D+01 13 11 1 2 12 0 0.0 4.300000000000D+01 4 08 9 27 4 0 0.0 7.400000000000D+01 5 11 9 19 6 0 0.0 2.600000000000D+01 6 11 1 2 11 59 44.0 0.000000000000D+00 37 11 1 2 2 0 0.0 4.700000000000D+01 28 11 1 2 4 0 0.0 4.900000000000D+01 9 10 6 19 10 0 0.0 3.600000000000D+01 10 11 1 2 4 0 0.0 7.200000000000D+01 11 11 1 1 22 0 0.0 5.700000000000D+01 12 11 1 6 10 0 0.0 8.000000000000D+01 33 11 1 2 12 0 0.0 3.200000000000D+01 14 11 1 2 12 0 0.0 6.300000000000D+01 45 11 1 2 8 0 0.0 4.300000000000D+01 16 11 1 3 11 59 44.0 5.000000000000D+00 */