J
Jean-Baptiste
How to convert a single string into UTF format.
str = "test"
strUTF = str. ?????
Thanks
str = "test"
strUTF = str. ?????
Thanks
How to convert a single string into UTF format.
Mark said:Which isn't much of a test since the UTF-8 of "test" is just "test".
This is a better demonstration:
irb(main):004:0> convertor.iconv("¡Hola!")
=> "\302\241Hola!"
The two-byte sequence "\302\241" - that is, a byte whose value is
octal 302 = decimal 194 = hexadecimal C2 followed by a byte whose value is
octal 241 = decimal 161 = hexadecimal A1, is, in fact, the UTF-8 encoding
of the character U+00A1 INVERTED EXCLAMATION MARK.
Mark said:Use the iconv library, which comes with Ruby 1.8.
You have to know
what encoding you're starting with - ISO-8859-1 (a.k.a Latin-1) or
whatever your local character set is. Note the order of arguments
in Iconv.open: the target character set comes first, then the source
character set.
irb(main):001:0> require 'iconv'
=> true
Piergiuliano said:Mark said:Use the iconv library, which comes with Ruby 1.8.
Is iconv available on Windows 1.8.0 PragProg distribution?
C:\TEMP\x>ruby -v
ruby 1.8.0 (2003-08-04) [i386-mswin32]
You have to know
what encoding you're starting with - ISO-8859-1 (a.k.a Latin-1) or
whatever your local character set is. Note the order of arguments
in Iconv.open: the target character set comes first, then the source
character set.
irb(main):001:0> require 'iconv'
=> true
Not for me:
irb(main):001:0> require 'iconv'
LoadError: No such file to load -- iconv
from (irb):1:in `require'
from (irb):1
irb(main):002:0> VERSION
=> "1.8.0"
Trying your code in a file named 'tryconv.rb':
require 'iconv'
convertor = Iconv.open("UTF-8", "ISO-8859-1")
strUTF = convertor.iconv("test")
I get:
C:\TEMP\x>ruby tryconv.rb
./iconv.rb:2: uninitialized constant Iconv (NameError)
from tryconv.rb:1:in `require'
from tryconv.rb:1
Emmanuel said:[...]Piergiuliano said:Is iconv available on Windows 1.8.0 PragProg distribution?
yes, i reported this recently. it's a pretty bad problem for me :O/
i hope somebody smarter than me will fix it...
I would like to point out that a port of this feature to windows isPiergiuliano said:Is iconv available on Windows 1.8.0 PragProg distribution?
[...]
yes, i reported this recently. it's a pretty bad problem for me :O/
i hope somebody smarter than me will fix it...
You are right, I'm sorry, I should have checked first.
Not a big issue for me, anyway, I'm just curious to understand how it
can work on Windows.
Cheers, Giuliano
Emmanuel said:unfortunately I think right now ruby does not support iconv at all on win32.
great :O)Hi,
At Mon, 22 Dec 2003 22:21:08 +0900,
Emmanuel Touzery wrote:
It's supported, if you have it installed and pass proper
options to configure.
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.