Fastest way to remove chars from string

前端 未结 7 1675
生来不讨喜
生来不讨喜 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

    String.Join(null, str.Split(new char[] { '\t', '\r', '\n' },
        StringSplitOptions.None));
    

    might give you a performance increase over using Aggregate() since Join() is designed for strings.

    EDIT:

    Actually, this might be even better:

    String.Concat(str.Split(new char[] { '\t', '\r', '\n' },
        StringSplitOptions.None));
    

提交回复
热议问题