A
Andy Dbest
Hi Guys,
I have a small code block that is frustrating me for some time now. I
want to search for some text in a file. Simple isnt it?
def read_file week_num
week_num = week_num.to_s
f = File.open("fixtures.txt", "r")
lines = f.readlines
#week_num = '1.'
lines.each do|line|
if line.chomp.eql? week_num
puts "Found the week number"
end
end
f.close
end
The above is the method, and I am searching for "1.". I am passing the
variable "week_num" and i even tried to convert it to string. The search
code as it is right now, does not output "Found the week number", even
though the file contains "1."
If i uncomment the line that assigns week_num to '1.' directly, then it
works. What am i doing wrong?
I have a small code block that is frustrating me for some time now. I
want to search for some text in a file. Simple isnt it?
def read_file week_num
week_num = week_num.to_s
f = File.open("fixtures.txt", "r")
lines = f.readlines
#week_num = '1.'
lines.each do|line|
if line.chomp.eql? week_num
puts "Found the week number"
end
end
f.close
end
The above is the method, and I am searching for "1.". I am passing the
variable "week_num" and i even tried to convert it to string. The search
code as it is right now, does not output "Found the week number", even
though the file contains "1."
If i uncomment the line that assigns week_num to '1.' directly, then it
works. What am i doing wrong?