From: Singeo Date: 2007-05-17T19:33:16+09:00 Subject: Re: Problem removing new line characters on Mac OS X Hermann, I followed Sebatian's advice to use print instead of puts and that solved my problem. But I would still like to understand how to remove the newline characters. Here's my code as it currently stands (with "rssfile.print line" in place of "rssfile.puts line"), hopefully it will help you see how I was trying to tackle the problem. require("rubygems") require("scrubyt") require ("open-uri") require 'time' require 'date' psi = Scrubyt::Extractor.define do fetch("http://app.nea.gov.sg/psi/") record("/html/body/div/table/tr/td/table/tbody/tr/td/div", { :generalize => true }) do title("/strong[1]/font[1]") item("/table/tbody/tr/td/table/tbody/tr", { :generalize => true }) do region("/td[1]") psi("/td[7]") aqd("/td[8]") end end end f = open("psiregions.xml", File::CREAT|File::TRUNC|File::RDWR) {|f| psi.to_xml.write(f, 1) } # Create the RSS file. rssfile = File.new("sgpsi.xml", "w") rssfile.puts('') rssfile.puts('') rssfile.puts(' ') rssfile.puts(' http://app.nea.gov.sg/psi/') rssfile.puts(' Singapore PSI Readings') #rssfile.puts(' Singapore PSI Readings' + Time.now.rfc2822 + '') rssfile.puts(' ' + Time.now.rfc2822 + '') rssfile.puts(' singeo@singeo.com.sg') File.open('psiregions.xml', 'r') do |f1| while line = f1.gets line=line.strip line.gsub!(//, "") line.gsub!(/<\/root>/, "") line.gsub!(//, "") line.gsub!(/<\/record>/, "") line.gsub!("24-hr", "Singapore 24-hr") line.gsub!("Region", "") line.gsub!("Sulphur Dioxide", "") line.gsub!(//, "") line.gsub!(/<\/region>/,":") line.gsub!(/<psi>/, " PSI Level ") line.gsub!(/<\/psi>/, "") line.gsub!(/<aqd>/, " - ") line.gsub!(/<\/aqd>/, "") line.gsub!(//, "" + Time.now.rfc2822 + "") line.gsub!(/<\/item>/, "\n") rssfile.print line end end rssfile.puts('') rssfile.puts('') rssfile.puts('') rssfile.close On May 17, 6:20 pm, Hermann Martinelli wrote: > Singeo wrote: > > Hi Hermann, just tried your suggestion of: > > > line.gsub!(/\015/, '') > > > still no success. I'm creating and running the file on a Mac. > > Are you shure that you it is not successful? > > It would be good to know how you read the lines, > how you (not) remove the carriage returns, > and how you perhaps put the lines together > (adding again \r characters by mistake?). > > Are you removing the carriage returns line > by line (in which case the chomp should be perfect) > or are you trying it as a whole, i.e. do you have > not only one line but a whole file in 'line'? > > Rather than an answer to these questions I would > prefer to see some more code of the whole part > from opening the file to writing back or putting > out the strings. > > Hermann