码迷,mamicode.com
首页 > Windows程序 > 详细

C#方法-去除代码前序号

时间:2016-06-06 16:16:32      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:

在拷贝网上代码时候,经常每行的首列会有序号,如果一两行我们可以手动去除,可是几百行的时候就会很蛋疼了。

下列事去除代码前序号的方法:

        // 去掉复制代码前面的序号
        static public string GetCode(string path = null)
        {
            if(path == null)
                path = @"E:/code.txt";
            string[] allCodeLine = System.IO.File.ReadAllLines(path, System.Text.Encoding.Unicode);

            System.Text.StringBuilder strb = new System.Text.StringBuilder();
            Enumerable.Range(0, allCodeLine.Count()).ToList().ForEach(x =>
            {
                string output = 
                    System.Text.RegularExpressions.Regex.Replace(allCodeLine[x].ToString().Trim(), "^(\\d*)", "");
                strb.AppendLine(output);
            });
            
            StreamWriter sw = new StreamWriter(path);
            sw.Write(strb.ToString());
            return strb.ToString();
        }  

 

C#方法-去除代码前序号

标签:

原文地址:http://www.cnblogs.com/leeafei/p/5563799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!