Normalize newlines in C#

前端 未结 8 2061
滥情空心
滥情空心 2020-12-03 06:48

I have a data stream that may contain \\r, \\n, \\r\\n, \\n\\r or any combination of them. Is there a simple way to normalize the data to make all of them simply become \\r

8条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:17

    A Regex would help.. could do something roughly like this..

    (\r\n|\n\n|\n\r|\r|\n) replace with \r\n

    This regex produced these results from the table posted (just testing left side) so a replace should normalize.

    \r   => \r 
    \n   => \n 
    \n\n => \n\n 
    \n\r => \n\r 
    \r\n => \r\n 
    \r\n => \r\n 
    \n   => \n 
    

提交回复
热议问题