using System;
using System.IO;
using System.Text ;
using System.Collections.Generic ;
using System.Threading.Tasks;
using System.Linq;
namespace shanchuzhushi
{
class MainClass
{
//边读边写方法.
static void Read(string lj)
{
bool pd = true;
string str = "";
string njl = lj.Insert(lj.IndexOf("."), "_copy");
using (StreamWriter writer = new StreamWriter (njl, false, Encoding.UTF8))
{
using (StreamReader reader = new StreamReader (lj, Encoding.UTF8))
{
while ((str = reader.ReadLine ()) != null)
{
if (!string.IsNullOrEmpty (str))
{ //判断字符串是否为空行;
if ((str.Trim ()).Length != 0)
{
if (str.IndexOf ("/*") != -1) //判断都找到的第一个"/*"的位置此时关闭读取一直到找到一个最近的"*/"为止
{
pd = false;
continue;
}
if (str.IndexOf ("*/") != -1) //当找到一个*/时,此时打开读写把读取到的内容重新写到一个文件夹中.
{
pd = true;
continue;
}
if (pd) // 此处是为了在注释时段内部的时候不进行读取
{
if (str.IndexOf ("//") != -1 && !str.Contains ('"')) //此时用来判断是否含有注释
{
str = str.Substring (0, str.IndexOf ("//"));//此时用来判断去除注释后为空行的代码.
if (str.Trim ().Length != 0)
{
writer.WriteLine (str);
}
} else
{
writer.WriteLine (str);
}
}
}
}
}
}
}
}
public static void Main (string[] args)
{
Console.WriteLine ("请输入你所要修改的路径");
string lj = Console.ReadLine ();
Read (lj);
Console.WriteLine ("修改注释中,请等待");
Console.WriteLine ("注释修改完成,请退出");
}
}
}