How to split a string while preserving line endings?

后端 未结 6 1274
谎友^
谎友^ 2021-01-01 06:02

I have a block of text and I want to get its lines without losing the \\r and \\n at the end. Right now, I have the following (suboptimal code):

<         


        
6条回答
  •  没有蜡笔的小新
    2021-01-01 06:44

    Something along the lines of using this regular expression: [^\n\r]*\r\n

    Then use Regex.Matches(). The problem is you need Group(1) out of each match and create your string list from that. In Python you'd just use the map() function. Not sure the best way to do it in .NET, you take it from there ;-)

提交回复
热议问题