剔除空调风格多行注释 [英] Strip out C Style Multi-line Comments
本文介绍了剔除空调风格多行注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一个通用方法的代码,通过一些标准C语言风格多行注释前面有一个C#字符串对象。
I have a C# string object that contains the code of a generic method, preceded by some standard C-Style multi-line comments.
我想我可以用 System.Text.RegularExpressions
删除注释块,但我似乎能够得到它的工作。
I figured I could use System.Text.RegularExpressions
to remove the comment block, but I can seem to be able to get it to work.
我想:?
code = Regex.Replace(code,@"/\*.*?\*/","");
我可以在正确的方向指出?
Can I be pointed in the right direction?
推荐答案
使用一个RegexOptions.Multiline选项参数。
Use a RegexOptions.Multiline option parameter.
string output = Regex.Replace(input, pattern, string.Empty, RegexOptions.Multiline);
完整的例子
string input = @"this is some stuff right here
/* blah blah blah
blah blah blah
blah blah blah */ and this is more stuff
right here.";
string pattern = @"/[*][\w\d\s]+[*]/";
string output = Regex.Replace(input, pattern, string.Empty, RegexOptions.Multiline);
Console.WriteLine(output);
这篇关于剔除空调风格多行注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文