my dog learned polymorphism
The moose likes Ruby and the fly likes Reading file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Reading file" Watch "Reading file" New topic

Reading file

amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 543
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 or and then 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.

Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

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.

A good workman is known by his tools.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 543
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.

I agree. Here's the link:
subject: Reading file
jQuery in Action, 3rd edition