Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if string is newline in C#

Tags:

c#

newline

I am somehow unable to determine whether a string is newline or not. The string which I use is read from a file written by Ultraedit using DOS Terminators CR/LF. I assume this would equate to "\r\n" or Environment.NewLine in C#. However , when I perform a comparison like this it always seem to return false :

if(str==Environment.NewLine)

Anyone with a clue on what's going on here?

like image 705
paradox Avatar asked Apr 30 '10 07:04

paradox


2 Answers

How are the lines read? If you're using StreamReader.ReadLine (or something similar), the new line character will not appear in the resulting string - it will be String.Empty or (i.e. "").

like image 181
Daniel Renshaw Avatar answered Oct 02 '22 22:10

Daniel Renshaw


Are you sure that the whole string only contains a NewLine and nothing more or less? Have you already tried str.Contains(Environment.NewLine)?

like image 45
Oliver Avatar answered Oct 02 '22 22:10

Oliver