Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRLF parsing blues in C#

Tags:

string

c#

I have the following code:

  string myTest = "Line1Test" + Environment.NewLine +
                  "Line2Test" + Environment.NewLine +
                  "Line3Test" + Environment.NewLine;
  string[] parseStr = myTest.Split(Environment.NewLine.ToCharArray());

What I'm getting is data every other line in the new array. I think this is because the split line is splitting for both line feeds and carriage returns, but how can I just get one element per line?

like image 226
Paul Michaels Avatar asked Nov 29 '22 04:11

Paul Michaels


1 Answers

string[] parseStr = myTest.Split(
    new string[] { Environment.NewLine },
    StringSplitOptions.None
);
like image 70
Dinah Avatar answered Dec 05 '22 15:12

Dinah