[MacRuby-devel] encoding mismatch ?

Yvon Thoraval yvon.thoraval at gmail.com
Thu Mar 11 08:46:59 PST 2010


I have to read an UTF-8 encoded file with accentuated chars.

if i do :

#! /usr/local/bin/macruby
# encoding: utf-8

SIGNATURES_FILE = "/Users/yt/dev/Signature/signatures.txt"
  open(SIGNATURES_FILE) do |file|
    file.each do |line|
      puts line
    end
  end

i get the correct characters on the Terminal, ie. :

...
-- 
« Pour ceux qui vont chercher midi à quatorze heures,
la minute de vérité risque de se faire longtemps attendre. »
(Pierre Dac)


however when doing (with or without the .force_encoding("UTF-8" and ,
"r:UTF-8") :

  t = "".force_encoding("UTF-8")
  open(SIGNATURES_FILE, "r:UTF-8") do |file|
     file.each do |line|
      t += line.force_encoding("UTF-8")
    end
  end
puts t

i get wrong chars :

...
-- 
« Pour ceux qui vont chercher midi à quatorze heures,
la minute de vérité risque de se faire longtemps attendre. »
(Pierre Dac)

the only difference is that i make use of a String t = ""

what did i missunderstood ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100311/b9cadf18/attachment.html>


More information about the MacRuby-devel mailing list