From: unbewusst.sein@... (=?ISO-8859-1?Q?Une_B=E9vue?=) Date: 2010-03-11T23:25:06+09:00 Subject: Re: reading an UTF-8 encoded file Une B�vue wrote: > right now, that's to say using puts in place of p, i get the right > chars. > But those strings are still taged by "US-ASCII"... however, when doing some spliting by : def get_signatures t = "".force_encoding("UTF-8") open(SIGNATURES_FILE, "r:UTF-8") do |file| #open(SIGNATURES_FILE) do |file| file.each do |line| t += line.force_encoding("UTF-8") end end #File.open(SIGNATURES_FILE, "r:UTF-8").each {|l| t += l } return t.split(NEEDLE) end (notice i've forced the encoding) signatures = get_signatures c = signatures.count puts "Nombre de signatures : #{c}" r = rand(c) puts "Signature al�atoire (n� #{r}) :" signature = NEEDLE + signatures[r] puts signature the output is wrong in that case ??? Nombre de signatures : 29 Signature al�atoire (n� 1) : -- �� Un banquier est toujours en libert�� provisoire �� (Henri Poincar�� ) -- � L'essence m�me du g�nie, c'est de mettre en pratique les id�es les plus simples. � (Charles Peguy)