# Newbie Question (gets.chomp)

**URL:** <https://www.ruby-forum.com/t/newbie-question-gets-chomp/108259>\
**Category:** Ruby\
**Created:** [July 1, 2007, 5:32am UTC](https://www.ruby-forum.com/t/newbie-question-gets-chomp/108259 "2007-07-01T05:32:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 1, 2007, 5:32am UTC](https://www.ruby-forum.com/t/newbie-question-gets-chomp/108259/1 "2007-07-01T05:32:36Z")

</div>

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.

thanks, seems like a simple question… but i couldn’t find anything on  
it in the forums

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [July 1, 2007, 11:47am UTC](https://www.ruby-forum.com/t/newbie-question-gets-chomp/108259/2 "2007-07-01T11:47:03Z")

</div>

-------- Original-Nachricht --------  
Datum: Sun, 1 Jul 2007 12:32:37 +0900  
Von: Guest [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
An: removed\_email\_address@domain.invalid  
Betreff: Newbie Question (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](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
