批量替换多个字符

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

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

image

原文地址:https://www.cnblogs.com/chenxizhang/p/1649101.html