Problems with Iconv

H

Horacio Sanson

I am trying to convert some text data read from a web page from one charset to
UTF-8 using Iconv but I am getting an IllegalSequence all the time.


I wrote a little script that reads a web page via Net::HTTP, after that I
simply pass the body of the web page to Iconv like this:


h = Net::HTTP.new(@uri.host,@uri.port)
@resp, @body = h.get(@uri.path, nil )
puts "Code = #{@resp.code}"
puts "Message = #{@resp.message}"
@resp.each {|key, val| printf "%-14s = %-40.40s\n", key, val }


#puts @body
puts Iconv.new("sjis", "utf8").iconv(@body)



when running this script I get

`iconv': "\223\374\216D\214\366\215\220" (Iconv::IllegalSequence)


I can use the iconv command line and I get the desired result... is Iconv
working properly? I am doing something wrong? or is there any other way to do
this??


thanks for any tips
Horacio
 
N

nobu.nokada

Hi,

At Sun, 23 Oct 2005 01:23:27 +0900,
Horacio Sanson wrote in [ruby-talk:162037]:
I am trying to convert some text data read from a web page from one charset to
UTF-8 using Iconv but I am getting an IllegalSequence all the time.
#puts @body
puts Iconv.new("sjis", "utf8").iconv(@body)

It will convert from UTF8 to SJIS.

Iconv.conv("utf8", "sjis", @body)

The order comes from iconv_open(3) defined by SUSv2.
 
H

Horacio Sanson

Thanks, this did the job...

Horacio

Sunday 23 October 2005 01:[email protected] =E3=81=95=E3=
=82=93=E3=81=AF=E6=9B=B8=E3=81=8D=E3=81=BE=E3=81=97=E3=81=9F:
Hi,

At Sun, 23 Oct 2005 01:23:27 +0900,

Horacio Sanson wrote in [ruby-talk:162037]:
I am trying to convert some text data read from a web page from one
charset to UTF-8 using Iconv but I am getting an IllegalSequence all the
time.

#puts @body
puts Iconv.new("sjis", "utf8").iconv(@body)

It will convert from UTF8 to SJIS.

Iconv.conv("utf8", "sjis", @body)

The order comes from iconv_open(3) defined by SUSv2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top