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

D

Dirk Einecke

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
 
T

ts

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

How have you created this file ?

It's encoded in UTF8


Guy Decoux
 
D

Dirk Einecke

Hi.
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
 
T

ts

D> The file was created with this code:

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

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

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

D> file.write(content)
D> file.close
D> end


Guy Decoux
 
A

Andreas Schwarz

ts said:
D> The file was created with this code:

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

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

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

Or better: use iconv.
 
D

Dirk Einecke

Hi.

Andreas said:
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
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top