From: Rainer Date: 2007-11-04T19:45:16+09:00 Subject: Re: The return of the son of Umlaute On 1 Nov., 16:24, ed.oda...@wonado.de wrote: > Take a look tohttp://www.gnu.org/software/libiconv/ > > I found there everything that is necessary to do the job :-) > > C:\Dokumente und Einstellungen\wolfgang>irb > irb(main):001:0> require 'iconv' > => true > irb(main):002:0> Iconv.iconv('utf-8', 'CP850', "äöü") > => ["\303\244\303\266\303\274"] > irb(main):003:0> Iconv.iconv('ISO-8859-1', 'CP850', "äöü") > => ["\344\366\374"] > > Wolfgang Nádasi-Donner > -- > Posted viahttp://www.ruby-forum.com/. Hello Wolfgang, thank you very much, the second line above did the trick, and it works both ways! The irony is that I actually had seen the libiconv page you referred me to. What I had failed to see was the fact that the long lists of character encodings and their explanations were meant to be THE ACTUAL STRINGS you had to replace for "to" and "from" in the iconv method. Argh! Thanks also to mortee and 7stud and to everyone who helped me on this. This newsgroup has been a wonderful experience so far. As a little "Thank you" to this group, I'm giving a short summary for anyone who gets stuck in the same place as me, written with a "cookbook approach" (sort of): PROBLEM: When you read text files and use their contents in irb, some of the characters look strange. REASON: The character encoding you are using for your text files is different from the one in your irb shell. SOLUTION: 1. Find out which character encoding is used in your irb shell. The solution for step 1 depends on your operating system. If you're working with Windows, open "cmd.exe" and type "chcp" at the prompt. If you're in Germany like me, you'll probably read this: > Aktive Codepage: 850. 2. Find out about the character encoding for your files. I didn't use a command line tool for this. In my case it's ISO-8859-1 (Western European countries). You will find a good introduction here: http://en.wikipedia.org/wiki/ISO_8859 (and here if you're German: http://de.wikipedia.org/wiki/ISO_8859). 3. Find the function to convert between the encodings. The function is Iconv.iconv(to, from, *strs) from the iconv standard library. An explanation for the character encodings used by iconv is here: http://www.gnu.org/software/libiconv/ 4. Find out what to replace for "to" and "from". This was the hard part for me. I failed to see that the explanations on the libiconv page are the actual strings you have to replace. Small excerpt: ----from libiconv page---- It provides support for the encodings: European languages ASCII, ISO-8859-{1,2,3,4,5,7,9,10,13,14,15,16}, KOI8-R, KOI8-U, KOI8- RU, CP{1250,1251,1252,1253,1254,1257}, CP{850,866}, Mac{Roman,CentralEurope,Iceland,Croatian,Romania}, Mac{Cyrillic,Ukraine,Greek,Turkish}, Macintosh ... ----from libiconv page---- This means (of course): 'ISO-8859-1' or 'ISO-8859-2' or 'CP850' or 'CP866' and so on. 5. The actual code for converting the strings back and forth on my Windows XP machine: require 'iconv' my_string = 'Motörhead' #Converting from the shell to a file shell_to_file = Iconv.iconv('ISO-8859-1', 'CP850', my_string) f = File.open("umlaut.txt", "w") f << shell_to_file f.close #Converting strings from the file in order to read it in the shell f = File.open("umlaut.txt", "r") string_from_file = f.readlines.first file_to_shell = Iconv.iconv('CP850', 'ISO-8859-1', string_from_file) That's it! What I'm trying to do here is putting Martin Fowlers tip "if I want to learn about something I write about it." to good use, so: Any comments and criticism to this solution are appreciated. Cheers, Rainer