这是我的字符串。脚本:
Select * from tablename()
/*
go
*/
我的代码看起来像这样
private string RemoveBetween(string editScript, char begin, char end)
{
Regex regex = new Regex(string.Format("///.*?///", begin, end));
return regex.Replace(editScript, string.Empty);
}
editscript = RemoveBetween(editscript, '/', '/');
AM无法删除/*----*/
之间的文字。
答案 0 :(得分:1)
private string RemoveBetween(String editScript, String begin, String end)
{
return Regex.Replace(editScript,
String.Format("{0}.*?{1}", begin, end),
String.Empty,
RegexOptions.Singleline)
}
用法:
editscript = RemoveBetween(editscript, "/", "/");
我已将您的签名更改为使用String
,因为您可能希望像这样调用它(删除SQL注释块):
editscript = RemoveBetween(editscript, "/\*", "\*/");