Hello everybody,

I'd like to get a hint about a little Ruby problem I'm dealing with.
In my spare time I wrote a little Ruby program with a plain text
interface for I/O. I use Windows XP (yeah, I know :-) with Ruby 1.8.6.

Now for the problem: In Germany, we have letters called "Umlaute",
which are rarely used in the English language. An example you might be
familiar with is the name ot the rock band "Mot=F6rhead". (No, I don't
know their music, it's just an example.)

Now, if I wanted to save a file with the single line "Mot=F6rhead", I
would want to do something like this:

irb(main):001:0> a_string =3D "Mot=F6rhead"
=3D> "Mot\224rhead"
irb(main):002:0> a_file =3D File.new("test.txt", "w")
=3D> #<File:test.txt>
irb(main):003:0> a_file << a_string
=3D> #<File:test.txt>
irb(main):004:0> a_file.close
=3D> nil
irb(main):005:0>

However, when I open "test.txt" with a text editor, I get this result:

Mot"rhead

When I read a file with the correct spelling...

irb(main):006:0> puts File.open("test.txt", "r").readlines

.=2EI get this result:

Mot=F7rhead
=3D> nil

I've tried to use Iconv, but I don't know the names of the character
sets I have to use. To solve the problem, I've written this little
script..

def umlaute (line, replace_dict =3D File_To_Shell)
  changed_line =3D line.clone
  replace_dict.each_pair {|from, to| changed_line.sub!(from, to)}
  changed_line
end

.=2E.which uses two hashes in order to replace the "offending"
characters back and forth:

File_To_Shell =3D {
  /\344/ =3D> "\204", # "=E4"
  /\366/ =3D> "\224", # "=F6"
  /\374/ =3D> "\201",  # "=FC"
  /\304/ =3D> "\216", # "=C4"
  /\326/ =3D> "\231", # "=D6"
  /\334/ =3D> "\232",  # "=DC"
  /\337/ =3D> "\341"  # "=DF"
}

Shell_To_File =3D {
  /\204/ =3D> "\344", # "=E4"
  /\224/ =3D> "\366", # "=F6"
  /\201/ =3D> "\374",  # "=FC"
  /\216/ =3D> "\304", # "=C4"
  /\231/ =3D> "\326", # "=D6"
  /\232/ =3D> "\334",  # "=DC"
  /\341/ =3D> "\337"  # "=DF"
}

This seems to work, but I consider this a rather ugly workaround and
hardly a decent solution, since it forces me to type..

a_string =3D umlaute("Mot=F6rhead")

.=2Eor even..

puts umlaute("Mot=F6rhead")

.=2Ewhenever I have a "strange" character or two in my strings. Any help
is appreciated.

Thanks in advance,

Rainer Wolf