c# - How to split a string while preserving line endings? -


I have a block of text and I want to lose my line without N Finally, I have the following (sub-code):

  string [] line = tbIn.Text.Split ('\ n'). Select (t = & gt; t.Replace ("\ R", "\ r \ n")). ToArray ();  

So I'm thinking - is there a better way to do this?

Approved Answers

  String [] line = Reggae. Sample (TBIN Text, @ "(? & Lt; = \ r \ n) (?! $)");  

The following seems to be done:

  string [] Line = Reggae Split (TBine text, @ "(? & Lt; = \ r \ n) (?! $)");  

(? & Lt; = \ r \ n) Uses 'positive constellation' to match after \ r \ n without using it.

(?! $) Uses negative attitudes to prevent matching at the end of the input and avoids the last line which is just an empty string.


Comments