zoukankan      html  css  js  c++  java
  • .NET 平台文件去除行号

     /*  

    说明:三控件,button1 开始,button2 复制代码.txt_file(TextBox控件) 显示文件路径,另外一个TextBox 显示结果。有个openfiledialog打开文件。

    */

    namespace 文件去除行号

    {

        public partial class Form1 : Form

            

        {

            bool isHasName = false;  //是否有文件

            string fileName = string.Empty; //文件名

     

     

            public Form1()

            {

                InitializeComponent();

            }

     

            private void button1_Click(object sender, EventArgs e)

            {

     

     

     

                if (DialogResult.OK == this.openFileDialog1.ShowDialog())

                {

     

                    this.txt_File.Text = this.openFileDialog1.FileName;

     

                    ModifyFile(this.openFileDialog1.FileName);

     

     

     

                }

               

             

            }

     

            public void ModifyFile(string fileName)

            {

                string message = string.Empty;

                try

                {

                    using (FileStream fs = new FileStream(@fileName, FileMode.Open, FileAccess.ReadWrite))

                    {

                        using (StreamReader sr = new StreamReader(fs))

                        {

     

     

     

                            this.textBox1.Text = "//转换过后的字符是" + Environment.NewLine + Regex.Replace(sr.ReadToEnd(), @"^\s*\d+", " ", RegexOptions.Multiline);

                            message = "转换成功";

     

                        }

                    }

                }

                catch (Exception ex)

                {

                    message = ex.Message;

     

                }

                finally

                {

                    MessageBox.Show(message);

                }

            }

     

            private void button2_Click(object sender, EventArgs e)

            {

                //MemoryStream ms = new MemoryStream();

                //this.textBox1.Save(ms, ImageFormat.Gif);

                //Clipboard.SetData(DataFormats.Bitmap, ms);

                //Image image = new Bitmap((MemoryStream)Clipboard.GetData(DataFormats.Bitmap));

                //pictureBox2.Image = image;

     

                //Clipboard.SetDataObject(Image.FromFile(openFileDialog1.FileName), false);

                if (!string.IsNullOrEmpty(this.textBox1.Text))

                {

                    Clipboard.SetText(this.textBox1.Text);

                    MessageBox.Show("复制成功!");

                }

                else

                {

                    return;

                }

            }

        }

    }

  • 相关阅读:
    主机访问虚拟机网络服务失败
    关于接收者为指针的方法
    slice的部分说明
    ES基础知识
    静态语言和动态语言
    数据库设计三大范式
    SparkSQL小例子
    spark小例子
    spark 分析作者发布文章的总阅读量
    spark和hadoop差异
  • 原文地址:https://www.cnblogs.com/fat_li/p/2050269.html
Copyright © 2011-2022 走看看