去掉文本中的空格

        private void getridofspace()
        {
            string new_text = null;
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "txt文件|*.txt|所有文件|*.*";
            of.AddExtension = true;
            of.Title = "打开文件";
            if (of.ShowDialog() == DialogResult.OK)
            {
                StreamReader rd = File.OpenText(of.FileName);
                string text = rd.ReadToEnd();
                string[] temp = text.Split(' ');
                for (int i = 0; i < temp.Length; i++)
                {
                    new_text += temp[i];
                }
                rd.Close();
            }
            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = "txt文件|*.txt|所有文件|*.*";
            sf.AddExtension = true;
            sf.Title = "另存为"
            if (sf.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(sf.FileName, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(new_text);
                sw.Flush();
                sw.Close();
                fs.Close();
            }
        }


 

      String..::.Replace 方法 (Char, Char)
      public string Replace(
          char oldValue,
          char newValue
      )
      String..::.Replace 方法 (String, String)
      public string Replace(
          string oldValue,
          string newValue
      )
posted @ 2009-05-12 14:45  emery  阅读(432)  评论(0编辑  收藏  举报