From: Tim Hunter Date: 2007-09-19T06:00:49+09:00 Subject: Re: removing newline from eachline in file Chuck Dawit wrote: > I'm reading a file line by line and trying to remove the newline at the > end of each line so that I can rebuild the url with the "www" and the > ".net" at the beginning and end. Does anyone know how I can remove the > newline char at the end of each line? Also if the url doesn't work/exist > I don't want the script to crash I want to keep moving through the file > its reading. ri String#chomp ----------------------------------------------------------- String#chomp str.chomp(separator=$/) => new_str ------------------------------------------------------------------------ Returns a new String with the given record separator removed from the end of str (if present). If $/ has not been changed from the default Ruby record separator, then chomp also removes carriage return characters (that is it will remove \n, \r, and \r\n). "hello".chomp #=> "hello" "hello\n".chomp #=> "hello" "hello\r\n".chomp #=> "hello" "hello\n\r".chomp #=> "hello\n" "hello\r".chomp #=> "hello" "hello \n there".chomp #=> "hello \n there" "hello".chomp("llo") #=> "he" -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]