From: Axel Etzold Date: 2007-07-01T18:46:24+09:00 Subject: Re: Newbie Question (gets.chomp) -------- Original-Nachricht -------- Datum: Sun, 1 Jul 2007 12:32:37 +0900 Von: Guest An: ruby-talk@ruby-lang.org Betreff: Newbie Question (gets.chomp) > Hiya > > just hoping someone can shed some light on this. If i were to prompt > the user to enter a search parameter to look across a bigger string of > text using: > > print "please enter search term: " > stdout.flush > string1 = gets.chomp > > i run into trouble when the user enters non english search terms. how > can i set this up to allow the user to enter other language words? > chinese/russian/etc. > Hello, this is due to different encodings used in the console and in the text document you're searching in. You can tell a Ruby script to use Unicode encoding by setting $KCODE='u' or use Iconv http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/classes/Iconv.html to convert between different encodings,e.g., if you need to convert from Western European ISO-8859-1 to UTF-8: require "Iconv" include Iconv puts "What do you want to search for?" search_what=gets.chomp search_what=Iconv.new('UTF-8', 'ISO-8859-1').iconv(search_what) # now, search for search_what (in UTF-8 encoding ) in a text # (which is also in UTF-8 encoding ) ... Best regards, Axel -- Psssst! Schon vom neuen GMX MultiMessenger geh�rt? Der kanns mit allen: http://www.gmx.net/de/go/multimessenger