-3

任何人都可以帮助我,如果它有像​​'//'或单行或多行评论'/*...*/'这样的评论,如何删除行

例如:

/\*#define                0x00000000*/

//#define                0x00180000

// #define                0x20000000

// abcd

/*#define                0x00080000

   #define               0x40000000*/

   #define               0x00014000 

   #define               0x00000800
/* defg  */

 #define                 0x00080000

 #define                 0x40000000

输出应该是

 #define               0x00014000 

 #define               0x00000800

 #define                 0x00080000

 #define                 0x40000000

在 C# 中使用正则表达式或任何其他方法,在此先感谢

4

2 回答 2

0

如果您的文件是这样格式化的,只需执行读取行并检查string.containt(...)/, *,”是否包含在您的字符串中。

如果是这种情况,只需将其删除。

提示:在列表中存储好行以显示您的输出。

希望这可以帮助你。

如果不后悔。

于 2013-06-04T12:23:51.363 回答
0

Alright, this Regex (^\/\/.*?$)|(\/\*.*?\*\/) (Rubular proof) will match (and potentially remove if you use Visual Studio and replace it with nothing) the following lines out of your example text:

//#define                0x00180000

// #define                0x20000000

// abcd

/*#define                0x00080000

   #define               0x40000000*/

/* defg  */

and almost gets you what you want. Now, I'm suspect of this line /\*#define 0x00000000*/, but if you wanted to capture it as well you could modify the Regex to be (^\/\/.*?$)|(\/.*?\*.*?\*\/) (Rubular proof).

于 2013-06-04T12:39:27.107 回答