Problems with Iconv

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

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.

···

--
Nobu Nakada

Thanks, this did the job...

Horacio

Sunday 23 October 2005 01:41、nobu.nokada@softhome.net さんは書きました:

···

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.