c#中有没有去掉一个字符串中的指定的某些字符?
1、String.Replace:
str = str.Replace("此银\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);
2、String.Aggregate:
string[] split = str.Split(new char[] { '\t', '\r', '\n' }, StringSplitOptions.None);
str = split.Aggregate<string>((str1, str2) => str1 + str2);
3、森绝宴Regex.Replace:
str = Regex.Replace(str, "[\r\n\t]", string.Empty, RegexOptions.Compiled);
4、Char Array:
string s = "abc";
int len = s.Length;
char[] s2 = new char[len];
int i2 = 0;
for (int i = 0; i < len; i++)
{
char c = s[i];
if (c != '宏慎\r' && c != '\n' && c != '\t')
s2[i2++] = c;
}
return new String(s2, 0, i2);
5、String.Concat:
String.Concat(str.Split(new char[] { '\t', '\r', '\n' },
StringSplitOptions.None));