I would like to make a program, which manipulates some files(writing stuff in). For that the best is, if i read characters in instead of lines. Anyone knows how i can detect if my character read in was a linebreak(OS free if possible)? My codepiece so far:
The "line.separator" property just tells you what the operating system thinks is a line break; it doesn't tell you anything about the file you're reading. To detect line breaks in a platform-neutral way, you have to look for '\n', '\r', or the two-character sequence "\r\n".
BTW, there's no need to convert the char to a string to do these tests, just do if (c == '\r') and if (c == '\n').
Joined: Oct 07, 2005
I was assuming you the files would have been created on the same OS that the program would be running on. But yes, checking for n and then r and then nr is much better.