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;

                }

            }

        }

    }

  • 相关阅读:
    VIM下的可视模式的相关知识
    VIM下的插入模式的相关知识:
    VIM下的普通模式的相关知识
    VIM中一些按键的作用:
    大师源于勤奋
    在你放弃以前,问问自己这6个问题
    一键查看IE密码!IE PassView简易教程
    如何查看Chrome浏览器保存的账号密码
    如何查看Firefox中保存的登录密码
    谈谈360浏览器保存密码的差异
  • 原文地址:https://www.cnblogs.com/fat_li/p/2050269.html
Copyright © 2011-2022 走看看