| |||||||||||||||||||||||||||||||
|
globalrev wrote: > On 8 Maj, 21:26, Adam Shelly <adam.she...> wrote: >> [aeiou] will match a vowel ... addition, you can use the abbreviations >> \s #whitespace >> >> > str = str.gsub(/([^\aeiouy])/,"\\1o\\1") >> >> I'd modify it to deal with case: >> str.gsub(/([^\saeiouy])/i){|c|"#{c}o#{c.downcase}"} >> >> will encode "Hi Oliver" into >> "Hohi Ololivoveror", instead of >> "HoHi OoOlolivoveror" >> >> HTH, >> -Adam > > is there some equally clever way to replace decode? > > puts "Enter code to decrypt: " > code = gets > x = 0 > dec = "" > while (x<code.length()) > dec = dec + code[x].chr > if code[x].chr !~ /[\saeiouy]/ > x = x + 2 > end > x = x + 1 > end > print dec Something like this: code.gsub(/([^\saeiouy])o([^\saeiouy])/){$1==$2 ? $1 : $& } Regards, Park Heesob -- Posted via http://www.ruby-forum.com/.
| ||||||||||||||||||||||||||||||
© 2004-2008 readlist.com