现在有一个文本文件,里面的内容如下,中间有很多空白行年份
2011/12
2010/12
2009/12
2008/12
2007/12盈利(百万)
46,055
26,836
19,618
13,029
27,678盈利增长(%)
71.62
36.79
50.57
-52.93
53.13现在想转成这样:年份
2011/12
2010/12
2009/12
2008/12
2007/12
盈利(百万)
46,055
26,836
19,618
13,029
27,678
盈利增长(%)
71.62
36.79
50.57
-52.93
53.13也就是去除掉中间的空白行,有什么简单易行的办法吗?

解决方案 »

  1.   

     Regex.Replace(yourText,@"\s+","\r\n");
      

  2.   


    System.IO.FileStream streamTxt = new System.IO.FileStream(AppDomain.CurrentDomain.BaseDirectory+"test.txt", System.IO.FileMode.Open);
    byte[] bytesTxt = new byte[streamTxt.Length];
    streamTxt.Read(bytesTxt, 0, bytesTxt.Length);
    string strTxt = System.Text.Encoding.Default.GetString(bytesTxt);
    strTxt=System.Text.RegularExpressions.Regex.Replace(strTxt, @"\s+", "\r\n");
    streamTxt.SetLength(0);
    streamTxt.Write(System.Text.Encoding.Default.GetBytes(strTxt), 0, System.Text.Encoding.Default.GetBytes(strTxt).Length);
    streamTxt.Close();