From: 7stud -- Date: 2012-10-31T11:08:39+09:00 Subject: Re: newline conversion on reading? Xavier Noria wrote in post #1082114: > I can't get newline conversions to work while reading: > > File.write('foo.txt', "foo\r\nbar\r\n") > If you are on a Window operating system, ruby will convert any "\n" in your output to "\r\n". So lets look through your output and convert any "\n" characters to "\r\n" to see what is actually written to the file. This line: foo\r..\n..bar\r..\n gets written as: because there are two "\n" characters that ruby converts to "\r\n" > > File.open('foo.txt', 'r', universal_newline: true) {|fh| fh.read} > # => "foo\r\nbar\r\n", no normalization performed > > Are they only supposed to work for writing? If yes, why the asymmetry? On Windows, the conversion that ruby performs when you read from a file is to convert any "\r\n" it sees to "\n", so this line in the file: foo\r..\r\n..bar..\r..\r\n gets read in as: foo\r..\n..bar..\r..\n -- Posted via http://www.ruby-forum.com/.