المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : File I/O - New Line Character



C# Programming
02-20-2010, 03:00 AM
I'm making changes to a file, saving the edits to a StringBuilder, then writing the mods to a temporary file before deleting the original and then renaming the temporary file.


Now, I want to be able to determine what new line character(s) to use for the file being modified.


At the moment if I look at the changes made to a text file from a UNIX machine with WinMerge, it'll show that every line has been modified because of the AppendLine() method of the StringBuilder, which defaults to I'm guessing "\r\n" where UNIX uses "\n".

"That's fine, I'll just use Append(..) then Append("\n")..." I thought.
But then WinMerge will highlight the same issue for Windows based text files that require "\r\n".


Currently I use a StreamReader.ReadLine() to whip through each line of the file, but that just consumes the EOL characters so I can't determine it that way.


Do I really have to Peek() through the file until I come accross the "\n" or "\r\n",
or is there a smarter way to do it?


Thanks y'all.

http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair

Now reading: 'The Third Reich', by Michael Burleigh