Dan Herrera wrote:
On Nov 1, 5:14 pm, [email protected] wrote:
Ruby RTF library. Creates RTF documents… might be a good start.
Hi, thanks for taking a look at my problem.
I am using the Ruby RTF library currently to generate RTF files. The
trouble I’m running into is with strings like ‘gï¿½r’. When you add
that ï¿½ character, it doesn’t get converted to it’s unicode counterpart
and the result is mangled when viewed.
A unicode has to be converted into a character language(called an
‘encoding’) that your display device can understand before the character
can be displayed. Common character languages(or ‘encodings’) are ascii
and utf-8. It sounds like the string you are starting with is encoded
in a character language that your display device doesn’t understand.
Therefore, you need to figure out what character language your display
device does understand. utf-8 is pretty common, so you can start off
trying to convert your strings to the utf-8 character language, and then
see if the strings will display correctly. But to convert your strings
to utf-8, you need to know the current character language that the
string is written in. If you don’t know the current language, you can
start off by trying ISO-8859-15. The characters that make up the
ISO-8859-15 language are listed here:
To convert from ISO-8859-15 to utf-8, you can do this:
str = “Hell\xf6 w\xf6rld” #\xf6 is ‘o’ with umlaut in ISO-8859-15
–output (which my display device shows me):–
Hell? w?rld #I see question marks instead of o’s with umlauts
Therefore, my display device does not understand the IS0-8859-15
character language. Since I want my display device to display the o’s
with umlauts, I’ll try converting the string to the utf-8 character
require ‘iconv’ #‘Internationalization converter’?
converter = Iconv.new(‘UTF-8’, ‘ISO-8859-15’)
new_str = converter.iconv(str)
HellÃ¶ wÃ¶rld #I see o’s with unlauts