批量替换多个字符

在字符处理过程中,我们可能需要对某些字符进行替换,而且可能会有多个字符,请比较下面两种写法:一个是用标准的replace函数,另外一个则是用正则表达式

string input = "1,;3^e";
string tt = input.Replace(",", "").Replace(";", "").Replace("^", "");
string rr = Regex.Replace(input, @",|;|\^", "");

Console.Write(tt + "\r\n" + rr);

posted @ 2013-07-22 22:52  pnljs  阅读(566)  评论(0编辑  收藏  举报