From: Todd Benson Date: 2008-05-09T00:52:05+09:00 Subject: Re: Check if char in string? On Thu, May 8, 2008 at 8:12 AM, Heesob Park wrote: > Hi, > > globalrev wrote: >> ty all for the help. haesob park did what iw anted. >> >> this is the program i wrote, it is an encrypter/decrypter for the >> robbers language(r�varspr�ket in swedish), its from the book Kalle >> Blomkvist by late and very famous author Astrid Lindgren. >> you add o + the consonant, nothing is done to vowels. >> so d becomes dod, a is just a. >> >> dad is therefore dodadod, super is sosupoperor etc. >> >> >> >> puts "Enter sentence to encrypt: " >> str = gets >> >> enc = "" >> for x in (0..str.length()-1) >> if str[x].chr =~ /[qwrtpsdfghjklzxcvbnm]/ >> enc = enc + str[x].chr + "o" + str[x].chr >> else >> enc = enc +str[x].chr >> end >> end >> >> print enc >> >> >> >> puts "Enter code to decrypt: " >> code = gets >> >> x = 0 >> dec = "" >> while (x> dec = dec + code[x].chr >> if code[x].chr =~ /[qwrtpsdfghjklzxcvbnm]/ >> x = x + 2 >> end >> x = x + 1 >> end >> >> print dec >> >> >> >> i then changed to !~ just like haesob said but if i do /aeiouy / it >> doesnt react to space " ". how do i get it to treat " " as "a"? > You can do with like this: > if str[x].chr !~ /[\saeiouy]/ > > BTW, your encryption equals to > str.gsub(/([^\saeiouy])/,"\\1o\\1") Not quite. [^\saeiouy] is not the same as the set of consonants. Todd