0

I have a line break in the middle of a line. Notepad shows it as one line however. It is not a Carriage Return, just a line feed. When I attempt to read the line using StreamReader.ReadLine(), it reads up to the LF, then stops, when I ReadLine again, it is the continuation. I have tried replace \n and \r to not avail.

Its not availbale because:

http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx

A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r") or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed. The returned value is nullNothingnullptra null reference (Nothing in Visual Basic) if the end of the input stream is reached.

Is there any workaround because i cant change the lines in the input file?

Update: See Notepad Screenshot paste.pics/f4f62d4b7636ff0f771693690757896c the lines are broken because of the linefeed but it should be one line my line end is \r\n and not \n

Aorus1337
  • 361
  • 1
  • 3
  • 6
  • So you want to treat only Carriage return as the new line character and not the line feed ? – Soumen Mukherjee Aug 19 '19 at 14:23
  • What happens when the line separator is \r\n? Do you want the \n as the start of the next line, or should it be ignored? Can you clarify exactly what the expected behaviour is? – Sean Reid Aug 19 '19 at 14:28
  • 2
    Can you provide sample input, cases when the line feed should split and when it should not, and expected output? Seems like `StreamReader.ReadLine()` is working as designed. – dvo Aug 19 '19 at 14:34
  • See Notepad Screenshot https://paste.pics/f4f62d4b7636ff0f771693690757896c the lines are broken because of the linefeed but it should be one line my line end is \r\n and not \n – Aorus1337 Aug 19 '19 at 14:54
  • look at this question. https://stackoverflow.com/questions/6655246/how-to-read-text-file-by-particular-line-separator-character – ClearLogic Aug 19 '19 at 15:40
  • See marked duplicate for lots of options to ignore `'\r'` as a line break. That said: just because Notepad doesn't recognize the line break as a line break, doesn't mean it's not a line break. See e.g. WordPad, which when you open the same file, _will_ show a line break there. What you really need to be asking is how did you get a file where the line break characters in use are not consistent. A lone `'\n'` is in fact a valid line break, for *nix-based systems and even certain Windows scenarios. So it's likely that line break was intentional. – Peter Duniho Aug 19 '19 at 17:14

0 Answers0