我有一个简单的基于regex替换的程序,有没有改善它的性能(也许还有它的优雅?)
public static string stripshrapnel(string str)
{
string newstr = str.Trim();
newstr = Regex.Replace(newstr, @"-", "");
newstr = Regex.Replace(newstr, @"'", "");
newstr = Regex.Replace(newstr, @",", "");
newstr = Regex.Replace(newstr, @"""", "");
newstr = Regex.Replace(newstr, @"\?", "");
newstr = Regex.Replace(newstr, @"\#", "");
newstr = Regex.Replace(newstr, @"\;", "");
newstr = Regex.Replace(newstr, @"\:", "");
//newstr = Regex.Replace(newstr, @"\(", "");
//newstr = Regex.Replace(newstr, @"\)", "");
newstr = Regex.Replace(newstr, @"\+", "");
newstr = Regex.Replace(newstr, @"\%", "");
newstr = Regex.Replace(newstr, @"\[", "");
newstr = Regex.Replace(newstr, @"\]", "");
newstr = Regex.Replace(newstr, @"\*", "");
newstr = Regex.Replace(newstr, @"\/", "");
newstr = Regex.Replace(newstr, @"\\", "");
newstr = Regex.Replace(newstr, @"&", "&");
newstr = Regex.Replace(newstr, @"&", "&");
newstr = Regex.Replace(newstr, @" ", " ");
newstr = Regex.Replace(newstr, @" ", " ");
return newstr;
}
谢谢您,
马特