标签:
在拷贝网上代码时候,经常每行的首列会有序号,如果一两行我们可以手动去除,可是几百行的时候就会很蛋疼了。
下列事去除代码前序号的方法:
// 去掉复制代码前面的序号 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(); }
标签:
原文地址:http://www.cnblogs.com/leeafei/p/5563799.html