From: Axel Etzold Date: 2008-08-18T22:39:14+09:00 Subject: Re: Ruby 1.8.* convert string to utf-8 -------- Original-Nachricht -------- > Datum: Mon, 18 Aug 2008 21:30:10 +0900 > Von: Pavel Drobushevich > An: ruby-talk@ruby-lang.org > Betreff: Ruby 1.8.* convert string to utf-8 > Hi all, > I has problem with convert string or file to utf-8 encoding. input file > can has different encoding. Ruby 1.9 has feature force_encoding of > String class. But in 1.8.* I found Iconv.conv('UTF-8', from, contents), > but I didn't find method to define input encoding. I found to ext libs: > 1. rchardet - but this lib incorrect define UCS-2LE encoding( > 2. libcharguess - butI can't male source to lib for ruby used > extconf.rb. > Please, help me to find other way, or anybody has ready libcharguess for > ruby. > Many thanks in advance. > -- > Posted via http://www.ruby-forum.com/. Dear Pavel, you can use "from" to define the input encoding, like so : require 'iconv' s =IO.read('kknta10.txt') ic = Iconv.iconv('utf-8', 'cp1251',s) f=File.new("t.txt","w") f.puts ic f.close I was able to convert a file in Windows-cp1251 by Pushkin as given in the Project Gutenberg (http://www.gutenberg.org/etext/5316) like this to utf-8 and I could open it in OpenOffice, to get clear text. You might also look here: http://markmail.org/message/btgxcrle666bgiiq#query:iconv%20ruby%20encodings%20cyrillic+page:1+mid:bursga6zqh6kvjl3+state:results Best regards, Axel -- GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen! Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx