1
我在桌面上編寫了下面的代碼,它工作正常。我在我的筆記本電腦上下載了它,下載了ruby(v1.9.3),並試圖運行它,但出現以下錯誤。我非常確定這是第一次使用Ruby,但在我第一次運行Ruby時從未在桌面上看到過這個問題。:字符串包含空字節Ruby
C:/Users/Downloads/vscript.rb:18:in 'initialize': string contains null byte (ArgumentError)
from C:/Users/Downloads/vscript.rb:18:in 'open'
from C:/Users/Downloads/vscript.rb:18:in 'main'
線18是File.open
行:
File.open("filename", "r") do |f|
# Do while there are characters in the text file
f.each do |line|
# Checks to see if any parts in file match the regex and inform the user
if x = line.match(/\d\.\d\.\d{4}\.\d/)
puts "#{x} was found in the file."
end
end
end
'vscript.rb'中的編碼是什麼?也許UTF-16? –
它以UTF-8編碼,沒有BOM –
你確定它是UTF-8嗎? UTF-8文本不應包含任何零字節,但UTF-16將包含大量零字節。 –