好的,我尝试从文件中删除包含 -- 的行。该文件如下所示:
-----------------------------------------------------------------
Lorem ipsum....
Text.....
我的代码:
f = File.open('C:\websites\ahr.txt')
f.each_line do |line|
if line.include? '-'
a = line
line.delete a
end
end
f = File.close
但它不会工作!我收到此错误:
file.rb:5:in `delete': invalid range "-- (ArgumentError)
" in string transliteration
from file.rb:5:in `block in <main>'
from file.rb:2:in `each_line'
from file.rb:2:in `<main>'
这是怎么回事?