0
class Comparer
words = "asdf-asdf-e-e-a-dsf-bvc-onetwothreefourfive-bob-john"
foundWords = []
File.foreach('words.txt') do |line|
substr = "#{line}"
if words.include? substr
puts "Found " + substr
foundWords << substr
end
end
wordList = foundWords.join("\n").to_s
puts "Words found: " + wordList
end
words.txt:
one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
我想代码返回的包括?不过当代码运行的所有实例,wordList只包含words.txt的最后一行(“onetwothreefour”)。为什么words.txt中的其他行不会被分解?
谢谢塞尔吉奥的快速和正确的答案! – user3782426