太简单了,把你上面那串东西当作一个字符串写进111这个文件中就行了
不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
StreamReader sr = File.OpenText(@"c:\log\1.txt"); StreamWriter sw = File.CreateText(@"c:\log\2.txt"); int[] num = new int[255]; string[] str = new string[255]; int positon = 0; string line,temp,pre; line = sr.ReadLine().TrimEnd(); while(line != null && line.Length > 5){ //MessageBox.Show(line.LastIndexOf(" ")+ " " + line.Length); temp = line.Substring(line.LastIndexOf(" ")+1,line.Length-line.LastIndexOf(" ")-1); str[positon] = line.Substring(0,line.LastIndexOf(" ")); num[positon] = Convert.ToInt32(temp); if(positon!=0 && num[positon]!= num[positon-1]) { pre = ""; for (int i =0;i< num[positon-1].ToString().Length;i++) pre += " "; sw.WriteLine(str[0] + pre + "1"); for (int i =1;i< positon-1;i++) sw.WriteLine(str[i] + pre + "2"); sw.WriteLine(str[positon-1] + pre + "3"); num = new int[255]; str = new string[255]; str[0] = line.Substring(0,line.LastIndexOf(" ")); num[0] = Convert.ToInt32(temp); positon = 0; } line = sr.ReadLine(); if (line != null) line = line.TrimEnd(); positon++; } pre = ""; for (int i =0;i< num[positon-1].ToString().Length;i++) pre += " "; sw.WriteLine(str[0] + pre + "1"); for (int i =1;i< positon-1;i++) sw.WriteLine(str[i] + pre + "2"); sw.WriteLine(str[positon-1] + pre + "3"); sr.Close(); sw.Close();