惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - 恩电

奇技淫巧:手工为FMS3安装Adobe Flash Media Encoder 2 Authentication Add-In Adobe Flash Media Development Server 3 is here! Ready?The Integrating Forum Is Here! The AspNetForum Reloaded (重装上阵) FreeTextBox License机制的粗浅分析 DevComponents TreeGX V2.2 来了 基于ASPNETFORUM开发的拼客社区系统进入全面内测阶段 遭遇sal.xls.exe - 恩电 - 博客园 个人住房按揭贷款计算器再次更新 受网友U2U之托,DevComponents出品的TreeGX最新版本Patch出炉 DevComponents.DotNetBar 5.9.0.2 patch For .Net framework 1.x & 2.0 is coming. 小议优化ASP.NET应用性能之ViewState篇 小议优化ASP.NET应用性能之Cache篇 巧用RamDisk为Resharper提速 DotNetBar 5.9 with Office 2007 style controls Released,Are you ready? cracked perfectly! MS出品的壁纸自动换(英化绿色版) 分享五一期间做的网页UI抓取小工具 让Xenocode Fox 2006永不过期 分享动态生成文字图片解决方案
去除代码行号的一个小程序(控制台版本)
恩电 · 2006-05-17 · via 博客园 - 恩电

清风竹林发布了去除代码行号的一个小程序,确实方便大家收集一些文章代码,但个人认为象这样的小东东,要使广大网友能拿来就用,用.Net 2.0做成WinForm,有点贵族化了,于是动手整出个平民化的控制台版本,可以清除指定的文本文件,也可以对指定目录进行批量清除,希望对大家有点作用。以下代码在.Net Framework1.1与.Net Framework2.0均可运行。

  1using System;
  2using System.IO;
  3using System.Text;
  4
  5namespace Ycweb
  6{
  7    /// <summary>
  8    /// Summary description for Class1.
  9    /// </summary>

 10    class CLN
 11    {
 12        /// <summary>
 13        /// The main entry point for the application.
 14        /// </summary>

 15        [STAThread]
 16        static void Main(string[] args)
 17        {
 18            //
 19            // TODO: Add code to start application here
 20            //
 21            if(args.Length<1)
 22            {
 23                Console.WriteLine("用法:\n\r\t CLN YourFile.TXT|YourDirectory");
 24            }

 25            else
 26            {
 27                string tmpArg=args[0];
 28
 29                if(tmpArg.StartsWith("/"|| tmpArg.StartsWith("?"))
 30                {
 31                    Console.WriteLine("用法:\n\r\t CLN YourFile.TXT|YourDirectory");
 32                }

 33                else
 34                {
 35                    //假定用户提供的参数为目录,则先判断目录是否存在,如果存在则遍历该目录下的所有文本文件并清除行号
 36                    if(System.IO.Directory.Exists(tmpArg))
 37                    {
 38                        Clear Line Numbers For Files In The Directory
 54                    }

 55                    else
 56                    {
 57                        Clear Line Numbers For The File
 69                    }

 70                }

 71            }

 72        }

 73    
 74        /// <summary>
 75        /// 清除指定文件中的行号
 76        /// </summary>
 77        /// <param name="fileName">文件名,含路径</param>
 78        /// <returns>清除结果信息</returns>

 79        public static string ClearLine(string fileName)
 80        {
 81            string result;
 82            FileInfo fi=new FileInfo(fileName);
 83            string strExtension =fi.Extension;
 84            try
 85            {
 86                using (StreamReader reader = new StreamReader(fileName, Encoding.Default, true))
 87                {
 88                    using (StreamWriter writer = new StreamWriter(fileName.Replace(strExtension,"_clear" + strExtension)))
 89                    {
 90                        char[] lineNum = "#0123456789".ToCharArray();
 91                        string code = null;
 92                        while ((code = reader.ReadLine()) != null)
 93                        {
 94                            code = code.TrimStart();
 95                            code = code.TrimStart(lineNum);
 96                            writer.WriteLine(code);
 97                        }

 98                    }

 99                }

100                result=string.Format("成功清除文件{0}的行号.",fileName);
101            }

102            catch
103            {
104                result=string.Format("清除文件{0}的行号失败.",fileName);
105            }

106
107            return result;
108        }

109    }

110
111}

112

立即下载源码(for vs2003)