Fastest way to remove chars from string

前端 未结 7 1692
生来不讨喜
生来不讨喜 2020-12-05 13:52

I have a string from which I have to remove following char: \'\\r\', \'\\n\', and \'\\t\'. I have tried three different ways of removing these char and benchmarked them so I

7条回答
  •  悲&欢浪女
    2020-12-05 14:46

    try this

    string str = "something \tis \nbetter than nothing";
    string removeChars = new String(new Char[]{'\n', '\t'});
    string newStr = new string(str.ToCharArray().Where(c => !removeChars.Contains(c)).ToArray());
    

提交回复
热议问题