日期:2014-05-18 浏览次数:20848 次
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx string pattern = @"(?i)(?<=\d+\s+)((\d+\s+){4})(\d+\s+\d+\.\d+\s*?(-?\d+\.[^+-]+?[+-]\d{2,}\s*?){4})(-?\d+\.[^+-]+?[+-]\d{2,})(?=\s)"; //替换 string begin_red = "<font color='Red'>"; string end_red = "</font>"; tempStr = Regex.Replace(tempStr, pattern, begin_red + "$1" + end_red + "$3" + begin_red + "$5" + end_red); /* 1 <font color='Red'>12 9 17 22 </font>0 0.0 2.342900261283D-04 1.500000000000D+01 2.828125000000D+01 5.904180000000D+05 <font color='Red'>2.000000000000D+00</font> 2 <font color='Red'>12 3 18 4 </font>0 0.0 3.832229413092D-04 2.000000000000D+00 0.000000000000D+00 7.218000000000D+03 <font color='Red'>3.000000000000D+00</font> 3 <font color='Red'>12 3 18 12 </font>0 0.0 2.402812242508D-05 4.300000000000D+01-8.521875000000D+01 3.847200000000D+04 <font color='Red'>2.000000000000D+00</font> 4 <font color='Red'>09 3 18 4 </font>0 0.0 1.261560246348D-04 7.400000000000D+01 3.546875000000D+01 7.218000000000D+03 <font color='Red'>3.000000000000D+00</font> 9 <font color='Red'>12 3 16 10 </font>0 0.0 1.455144956708D-04 3.600000000000D+01 7.240625000000D+01 2.881800000000D+04 <font color='Red'>4.000000000000D+00</font> 10 <font color='Red'>12 3 18 4 </font>0 0.0-3.260467201471D-05 7.200000000000D+01 1.062500000000D+00 7.218000000000D+03 <font color='Red'>5.000000000000D+00</font> 51 <font color='Red'>12 3 17 22 </font>0 0.0-2.426193095744D-04