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

→‎{{header|Ruby}}: Switch from reading the DATA handle to reading a file.
(→‎{{header|Ruby}}: Switch from reading the DATA handle to reading a file.)
Line 544:
 
=={{header|Ruby}}==
{{works with|Ruby|1.9}}
Utf-8 is the default encoding since Ruby 2.0. In Ruby 1.9 use the magic comment "#encoding: utf-8" on the first line.
<lang ruby>DATA.each_char{|c| p c}
 
<lang ruby>File.open('input.txt', 'r:utf-8') do |f|
__END__
<lang ruby>DATA f.each_char{|c| p c}
characters: λ, α, γ</lang>
end</lang>
 
or
 
<lang ruby>File.open('input.txt', 'r:utf-8') do |f|
while c = f.getc
p c
end
end</lang>
 
=={{header|Run BASIC}}==
Anonymous user