• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading file

 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am storing some text in the file and want to use the same for comparison with another string.
Trying to read the file using IO.read() or file.open() and then file.read() but it returns me the string with escape characters in it. String with which I need to do the comparison does not have escape characters and hence I do not want Ruby to return me the file contents with escape characters in the file content string.
Appreciate and thank you in advance for your help.

Regards,
Amit
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably the safest thing is to call delete or gsub on the file content string before running your comparison to make these kinds of minor adjustments.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks and appreciate, Marc for your response.
I was printing the content on the console using "p" and copying it to the file for comparison later (regression test pack).
However, I noticed that if I use "puts" to print the content to be copied, it does not include these escape characters.
I have resolved it this way.

Thanks once again for your time.

Regards,
Amit
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic