Jump to content

Read a file character by character/UTF8: Difference between revisions

No edit summary
Line 85:
{{trans|Ruby}}
 
The encoding is UTF-8 by default, but it can be explicitly specified.
<lang ruby>File.open("input.txt", encoding: "UTF-8") do |file|
 
<lang ruby>File.open("input.txt", encoding: "UTF-8") do |file|
file.each_char { |c| p c }
end</lang>
Line 91 ⟶ 93:
or
 
<lang ruby>File.open("input.txt", encoding: "UTF-8") do |file|
while c = file.read_char
p c
end
end</lang>
 
 
=={{header|Déjà Vu}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.