Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Newbie Question (gets.chomp
guest
7/1/2007 3:33:00 AM
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
--
Posted via
http://www.ruby-...
.
1 Answer
Axel Etzold
7/1/2007 9:46:00 AM
0
-------- Original-Nachricht --------
Datum: Sun, 1 Jul 2007 12:32:37 +0900
Von: Guest <Guest@bugmenot.com>
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/...
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/mult...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Newbie Question (gets.chomp
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password