去除代码行号的一个小程序

 今天游览博客园,看别人的代码,觉得写得不错,想copy下来,无奈代码却有行号,我一向是先把代码copy下来然后一行一行的去除的,不过想想以后如果总是这么做的话也太麻烦了,于是终于决定写一个工具软件来做这件事情,共享给大家,希望能有所帮助。程序基于Microsoft Visual Studio 2005,主要代码如下:
 1 None.gif using  System;
 2 None.gif using  System.Collections.Generic;
 3 None.gif using  System.ComponentModel;
 4 None.gif using  System.Data;
 5 None.gif using  System.Drawing;
 6 None.gif using  System.Text;
 7 None.gif using  System.Windows.Forms;
 8 None.gif
 9 None.gif using  System.IO;
10 None.gif namespace  ClearCodeLineNum
11 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
12InBlock.gif    public partial class Form1 : Form
13ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
14InBlock.gif        public Form1()
15ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
16InBlock.gif            InitializeComponent();
17InBlock.gif
18InBlock.gif            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
19InBlock.gif            openFileDialog1.FileName = null;
20ExpandedSubBlockEnd.gif        }

21InBlock.gif
22InBlock.gif        private void btnOpenFile_Click(object sender, EventArgs e)
23ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
24InBlock.gif            if (openFileDialog1.ShowDialog() == DialogResult.OK)
25ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
26InBlock.gif                txtFilePath.Text = openFileDialog1.FileName;
27InBlock.gif                btnClearCode.Focus();
28ExpandedSubBlockEnd.gif            }

29ExpandedSubBlockEnd.gif        }

30InBlock.gif
31InBlock.gif        private void btnClearCode_Click(object sender, EventArgs e)
32ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
33InBlock.gif            if (File.Exists(txtFilePath.Text))
34ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
35InBlock.gif                using (StreamReader reader = new StreamReader(txtFilePath.Text, Encoding.Default, true))
36ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
37InBlock.gif                    int index = txtFilePath.Text.LastIndexOf('.');
38InBlock.gif
39ExpandedSubBlockStart.gifContractedSubBlock.gif                    /**////strExtension is the file extension, we need to maintain the 
40ExpandedSubBlockEnd.gif                    ///cleared file's extension

41InBlock.gif                    string strExtension = txtFilePath.Text.Substring(index);
42InBlock.gif                    using (StreamWriter writer = new StreamWriter(txtFilePath.Text + ".clear" + strExtension))
43ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
44ExpandedSubBlockStart.gifContractedSubBlock.gif                        /**////lineNum will be the array of numbers that need removing
45ExpandedSubBlockEnd.gif                        ///from every line code.

46InBlock.gif                        char[] lineNum = "0123456789".ToCharArray();
47InBlock.gif                        string code = null;
48InBlock.gif                        while ((code = reader.ReadLine()) != null)
49ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
50ExpandedSubBlockStart.gifContractedSubBlock.gif                            /**////remove the spaces at the front of the line,otherwise 
51ExpandedSubBlockEnd.gif                            ///it will stop the operation of the next line code.

52InBlock.gif                            code = code.TrimStart();
53InBlock.gif                            code = code.TrimStart(lineNum);
54InBlock.gif                            writer.WriteLine(code);
55ExpandedSubBlockEnd.gif                        }

56ExpandedSubBlockEnd.gif                    }

57ExpandedSubBlockEnd.gif                }

58InBlock.gif                MessageBox.Show("成功去除行号""清风竹林", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
59ExpandedSubBlockEnd.gif            }

60InBlock.gif            btnOpenFile.Focus();
61ExpandedSubBlockEnd.gif        }

62InBlock.gif
63InBlock.gif        private void btnCopyPath_Click(object sender, EventArgs e)
64ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
65InBlock.gif            if (File.Exists(txtFilePath.Text))
66ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
67InBlock.gif                FileInfo fileInfo = new FileInfo(txtFilePath.Text);
68InBlock.gif                System.Diagnostics.Process.Start(fileInfo.DirectoryName);
69InBlock.gif                btnOpenFile.Focus();
70ExpandedSubBlockEnd.gif            }

71ExpandedSubBlockEnd.gif        }

72ExpandedSubBlockEnd.gif    }

73ExpandedBlockEnd.gif}
呵呵,现在好了,如上面的代码,只要copy下来保存成文本,用本程序就可以很容易的去除了。
 源代码下载:  ClearCodeLineNum.rar

转载于:https://www.cnblogs.com/flappy/archive/2006/05/11/397769.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值