时间:2021-05-20
复制代码 代码如下:
using System.IO;
using System.Collections;
static string deleteComments(string s) //去掉以//开始的注释
{
if (s == null) return s;
int pos = s.IndexOf("//");
if (pos < 0) return s;
return s.Substring(0, pos);
}
if (Directory.Exists("Temp"))
Directory.Delete("Temp");
if (File.Exists("Generator.cmd"))
File.Delete("Generator.cmd");
if (File.Exists("rem.txt"))
File.Delete("rem.txt");
Directory.CreateDirectory("Temp");
DirectoryInfo dir = new DirectoryInfo(".");
ArrayList folders = new ArrayList();
FileSystemInfo[] fileArr = dir.GetFileSystemInfos();
folders.AddRange(fileArr);
for (int i = 0; i < folders.Count; i++)
{
FileInfo f = folders[i] as FileInfo;
if (f == null)
{
DirectoryInfo d = folders[i] as DirectoryInfo;
if (!d.Name.Contains("Debug") && !d.Name.Contains("Release") && d.Name!="Temp")
{
Directory.CreateDirectory("Temp" + "\\" + d.Name);
folders.AddRange(d.GetFileSystemInfos());
}
}
else
{
string str = f.FullName;
if (Path.GetExtension(f.FullName) == ".c" || Path.GetExtension(f.FullName) == ".cpp" || Path.GetExtension(f.FullName) == ".h" || Path.GetExtension(f.FullName) == ".hpp" || Path.GetExtension(f.FullName) == ".cxx" || Path.GetExtension(f.FullName) == ".cs")
{
try
{
FileStream fin = new FileStream(
f.FullName, FileMode.Open, FileAccess.Read);
FileStream fout = new FileStream(
str.Replace(Directory.GetCurrentDirectory(), Directory.GetCurrentDirectory() + "\\Temp"), FileMode.Create, FileAccess.Write);
StreamReader brin = new StreamReader(
fin, System.Text.Encoding.Default);
StreamWriter brout = new StreamWriter(
fout, System.Text.Encoding.Default);
string s = brin.ReadLine();
while (s != null)
{
s = deleteComments(s); //去掉以//开始的注释
brout.WriteLine(s); //写出
Console.WriteLine(s); //在控制上显示
s = brin.ReadLine(); //读入
}
brin.Close(); // 关闭缓冲读入流及文件读入流的连接.
brout.Close();
}
catch (FileNotFoundException)
{
Console.WriteLine("File not found!");
}
catch (IOException e2)
{
Console.WriteLine(e2);
}
}
else
File.Copy(f.FullName, str.Replace(Directory.GetCurrentDirectory(), Directory.GetCurrentDirectory() + "\\Temp"));
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
去除C代码中的注释,1.单行注释//;2.多行注释;3.单行注释以“\”结尾则下一行也为注释;4.字符串中的注释不处理。说是C语言,但其实所有C语系的都
C#Coding的时候,常常涉及代码注释,常见的注释包括两类:1)单行注释。格式://Comments2)多行注释。格式:C#引入
一、python单行注释符号(#)python中单行注释采用#开头示例:#thisisacomment二、批量、多行注释符号多行注释是用三引号”'”'包含的,例
c语言的注释定界符是什么1、最早期的C语言注释是:2、后来又增加的行注释://其中是多行注释,//是单行注释。需要注意的是:C语言的注释并不是可
javascript注释代码一般有两种方法:单行注释多行注释javascript单行注释单行注释以"//"开头,到改行的末尾结束。下面是javascript单行