From: Brian Candler Date: 2011-09-30T23:01:34+09:00 Subject: Re: IO.readlines will not accept variable with file name Why? Peter Vandenabeele wrote in post #1024278: >> Peter is there any difference between chomp and >> This: >> string = string.gsub(/\n/," ") >> chomp looks easier to remember. > > Well yes, a lot of difference ... > > gsub(/\n/, "") will produce a new string, where occurences of a newline > character ("\n") are replaced with a space. > > chomp will remove the last newline/carriage return combination > (0 or 1 CR and 0 or 1 LF if I am right). chomp does also produce a new string: irb(main):010:0> a = "abc\n" => "abc\n" irb(main):011:0> a.chomp => "abc" irb(main):012:0> a => "abc\n" But I think chomp is roughly equivalent to gsub(/\r?\n?\z/, '') -- Posted via http://www.ruby-forum.com/.