110,534
社区成员
发帖
与我相关
我的任务
分享
string s1 = "abcd/*gddgdg*/efg"; //s1为待处理的字符串
string strtmp,s2; //s2为处理后的字符串
int begin, end; //begin用于记录"/*"的位置,end用于记录"*/"的位置
strtmp=s1.Replace("/*", "{");
strtmp=strtmp.Replace("*/", "}"); //如果是"/*...*/"的话,先将其转换为"{..}"形式
begin = strtmp.IndexOf("{");
end = strtmp.IndexOf("}");
s2 = strtmp.Substring(0, begin) +strtmp.Substring(end+1,(strtmp.Length-end-1));
string result = Regex.Replace(yourStr, @"/\*(?:(?!\*/)[\s\S])*\*/|{[^}]*}", "");
using System.Text.RegularExpressions;
string str="你的字符串";
str=Regex.Replace(str,@"{[^}]*}|/\*[^\/]*?\*/","");
using System.Text.RegularExpressions;
string str="你的字符串";
str=Regex.Replace(str,@"{[\s\S]*?}|/\*[\s\S]*?\*/","");