Conserving Line Endings in a Text File

My application reads and parses text files. Some of these text files have a combination CR/LF as a line ending and I need to conserve those line ending characters - or at least replace them with the same number of white space characters.

I am using a text input stream to read a line at a time and see that the CR/LF characters are being replaced with a single space.

Is there a special encoding i can use that will preserve the original CR/LF characters or replace them with 2 white space characters ?

Thanks in advance

Ron Bower

ReadLine - by definition - splits the text up at line endings (regardless)
So you cant know for sure which line ending was in use
A single file could mix them
I forget if readline will handle that or if it just sticks to the first one found

Either read the whole file at once or read it in large chunks ignoring the end of lines into a long string

Then you could use ReplaceAll in 3 passes to replace

  1. CR/LF with 2 spaces + EndofLine
  2. CR with one space + EndOfline
  3. LF with one space + ENdOfLIne

Then split the whole thing on “EndOfLIne” so you have the spaces & split lines

Thanks for the quick and complete reply, Norman. I’ll have to look at some options.