C#简单的消除注释

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 ("注释修改完成,请退出");
		}
	}
}

  

转载于:https://www.cnblogs.com/mafeihao/p/9988702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值