我有一个名为region.txt的文件,它的数据如下:
shell.SetMyFile "Ranger"
shell.SetMyErrorFile "Discovery"
shell.SetMyFileEnabled 1
shell.SetMyLogFileEnabled 1
现在我正在使用 ruby 读取此文件,并尝试将“shell.SetMyFile”和“shell.SetMyErrorFile”中的文本过滤为Ranger和Discovery:
File.readlines("regional.txt").each do |line|
value1 = line.split(" ")[1] if line.include?("shell.SetMyFile")
value2 = line.split(" ")[1] if line.include?("shell.SetMyErrorFile ")
puts value1, value2
end
我的结果是1 , 1而不是Ranger和Discovery。这是因为包括?考虑到 "shell.SetMyFileEnabled"和"shell.SetMyLogFileEnabled"的方法。如何将其过滤到所需的结果?