From: Park Heesob Date: 2005-08-12T10:14:24+09:00 Subject: Re: UTF-8 encoding Hi, ----- Original Message ----- From: Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Friday, August 12, 2005 6:31 AM Subject: Re: UTF-8 encoding > > > Dave Burt skrev: >> balony@gmail.com wrote: >> > >> > Im working with xmprpc/client and the server Im working against >> > requires utf8 for my strings. >> > >> > I found this article with google: >> > http://redhanded.hobix.com/inspect/futurismUnicodeInRuby.html >> > >> > Is this for real? Is there no workaround for me to get my data to the >> > server with uft8 encoding? >> >> You can use iconv or you can run an external pipe through GNU recode. >> >> utf8_string = Iconv.new('iso-8859-1', 'utf-8').iconv(iso_8859_string) > > I'm running on a windows system, that could be a problem? > Also i'm getting "test.rb:4: uninitialized constant Iconv (NameError)" > when testing. > > -- > Martin > Try this: def encode(str) begin require 'Win32API' str += "\0" ostr = "\0" * 256 multiByteToWideChar = Win32API.new('kernel32','MultiByteToWideChar',['L','L','P','L','P','L'],'L') multiByteToWideChar.Call(0,0,str,-1,ostr,128) (ostr.strip + "\0").unpack("S*").pack("U*") rescue LoadError require 'iconv' Iconv::iconv('iso-8859-1','UTF-8',str)[0] end end utf8_string = encode(iso_8859_string) Regards, Park Heesob