ruby每行比较只返回最后一个字符串
代码:ruby每行比较只返回最后一个字符串,ruby,Ruby,代码: 我希望代码返回include?的所有实例,但是当代码运行时,wordList只包含words.txt的最后一行(“onetwotree.”)。为什么words.txt中的其他行不被分解呢?因为您希望找到的所有其他行的末尾都有“隐藏”的换行符。你可以自己看 one blah-blah-blah 123-5342-123123 onetwo onetwothree onetwothreefour 您可以使用chomp来删除换行符方法在行 File.foreach('words.txt')
我希望代码返回include?的所有实例,但是当代码运行时,wordList只包含words.txt的最后一行(“onetwotree.”)。为什么words.txt中的其他行不被分解呢?因为您希望找到的所有其他行的末尾都有“隐藏”的换行符。你可以自己看
one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用chomp来删除换行符代码>方法在行
File.foreach('words.txt') do |line|
puts line.inspect
# or
p line
end
由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看
one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用chomp来删除换行符代码>方法在行
File.foreach('words.txt') do |line|
puts line.inspect
# or
p line
end
由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看
one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用chomp来删除换行符代码>方法在行
File.foreach('words.txt') do |line|
puts line.inspect
# or
p line
end
由于您希望找到的所有其他行,因此它们在末尾具有“隐藏”换行符。你可以自己看
one
blah-blah-blah
123-5342-123123
onetwo
onetwothree
onetwothreefour
您可以使用chomp来删除换行符代码>方法在行
File.foreach('words.txt') do |line|
puts line.inspect
# or
p line
end