Replace Line Breaks in a String C#

后端 未结 17 1106
失恋的感觉
失恋的感觉 2020-11-22 11:16

How can I replace Line Breaks within a string in C#?

17条回答
  •  误落风尘
    2020-11-22 11:43

    To make sure all possible ways of line breaks (Windows, Mac and Unix) are replaced you should use:

    string.Replace("\r\n", "\n").Replace('\r', '\n').Replace('\n', 'replacement');
    

    and in this order, to not to make extra line breaks, when you find some combination of line ending chars.

提交回复
热议问题