i convert line endings in file dos format unix format in c#.
unix systems use linefeed character (lf) line separator. notable exception microsoft windows, uses carriage return followed linefeed (crlf).
how change line endings in file dos unix format using c#. need guidance on converting this.
here answer convert files dos unix , back:
private void dos2unix(string filename) { const byte cr = 0x0d; const byte lf = 0x0a; byte[] data = file.readallbytes(filename); using (filestream filestream = file.openwrite(filename)) { binarywriter bw = new binarywriter(filestream); int position = 0; int index = 0; { index = array.indexof<byte>(data, cr, position); if ((index >= 0) && (data[index + 1] == lf)) { // write before cr bw.write(data, position, index - position); // lf position = index + 1; } } while (index >= 0); bw.write(data, position, data.length - position); filestream.setlength(filestream.position); } }
Comments
Post a Comment