Problem with special characters like üöä (german: umlaut)

Hi.

If I make this:
print ‘üöä’

… all is okay. But if I read [1] a file with the content ‘üöä’ and
print the content I get this: öüä. This is very strange. Can anybody
help me with this problem?

[1]
file = File.open(ENV[‘DOCUMENT_ROOT’] + “test5.temp”, File::RDONLY)
while line = file.gets do
print line
end
file.close

bye
Dirk Einecke

.... all is okay. But if I read [1] a file with the content 'üöä' and
print the content I get this: öüä. This is very strange. Can anybody
help me with this problem?

How have you created this file ?

It's encoded in UTF8

Guy Decoux

Hi.

ts wrote:

How have you created this file ?

It’s encoded in UTF8

The file was created with this code:

def writeMyFile(path,content)
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
content = CGI::unescapeHTML(content)
file.write(content)
file.close
end

What can I change?

bye
Dirk Einecke

The file was created with this code:

Well, if you are sure that it's encoded in UTF8

def writeMyFile(path,content)
   file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
     content = CGI::unescapeHTML(content)

        content = content.unpack("U*").pack("c*")

     file.write(content)
   file.close
end

Guy Decoux

ts wrote:

The file was created with this code:

Well, if you are sure that it’s encoded in UTF8

def writeMyFile(path,content)
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
content = CGI::unescapeHTML(content)

    content = content.unpack("U*").pack("c*") 

Or better: use iconv.

Hi.

ts wrote:

    content = content.unpack("U*").pack("c*") 

Thank you. Very much better now.

bye
Dirk Einecke

Any documentation for iconv?

Guillaume.

···

Le 12 avr. 04, à 06:39, Andreas Schwarz a écrit :

ts wrote:

The file was created with this code:

Well, if you are sure that it’s encoded in UTF8

def writeMyFile(path,content)
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
content = CGI::unescapeHTML(content)

    content = content.unpack("U*").pack("c*")

Or better: use iconv.

Guillaume Marcais wrote:

ts wrote:

The file was created with this code:

Well, if you are sure that it’s encoded in UTF8

def writeMyFile(path,content)
file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
content = CGI::unescapeHTML(content)

    content = content.unpack("U*").pack("c*")

Or better: use iconv.

Any documentation for iconv?

ruby-iconv is very poorly documented
(http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/), but it is easy to
use:

converted_text = Iconv.new(‘iso-8859-15’, ‘utf-8’).iconv(text)

···

Le 12 avr. 04, à 06:39, Andreas Schwarz a écrit :

Hi.

Andreas Schwarz wrote:

converted_text = Iconv.new(‘iso-8859-15’, ‘utf-8’).iconv(text)

That’s not working in my example and I don’t know how. Well - unpack and
pack is working so I use this. Thanks for your help.

bye
Dirk Einecke