wired result
by Cheyne Li other posts by this author
May 8 2008 1:27PM messages near this date
Write Ruby code sentences
|
Re: wired result
Hey, guys.
I'm a new ruby learner. I'm so stuck on the regular expression part.
The following code is a fuction that passed in 2 strings: ftarget, which
is the location of a file to read; fkey is the key to match in the file.
The function simply does open the file, read each line and try to find
if there is a match fkey.
I tested the
i=0
line.scan(fkey){|x|i=i+1}
puts i
if i> 0
puts "Found match...\n\r"
end
def fcmp(ftarget,fkey)
@argc=ftarget
puts fkey
unless ftest(ftarget)
puts "Invalid File name"
return false
end
File.open(ftarget, 'r') do |f1|
while line = f1.gets
puts line
i=0
line.scan(fkey){|x|i=i+1}
puts i
if i> 0
puts "Found match...\n\r"
end
#return false
end
end
end
--
Posted via http://www.ruby-forum.com/.
Thread:
Cheyne Li
Cheyne Li
Che
Michael Linfield
Cheyne Li
|