From: 7stud -- Date: 2011-03-04T09:17:27+09:00 Subject: Re: How can i get the first letter of this string duc nguyen wrote in post #985120: > thanks for your help! > My strings are in UTF-8 encoding. Ruby version 1.8.7 > > I just follow your instructions and got the first letter of that string. > But i still not get the remainder of string after get the first letter. > # encoding:utf-8 "á is the first letter" =~ /^(.)(.*)/u puts "-->#{$1}<--" puts "-->#{$2}<--" --output:-- -->á<-- --> is the first letter<-- > My problem now is convert the UTF-8 string to ansi string. > ex: purpose: change "âêơíũ" to "aeoiu". > I really confuse and don't have any way to do that. > # encoding:utf-8 "â is the first letter" =~ /^(.)(.*)/u conversion_hash = { 'â' => 'a', 'ê' => 'e', 'ơ' => 'o', 'í' => 'i', 'ũ' => 'u' } puts "#{conversion_hash[$1]}#{$2}" --output:-- a is the first letter -- Posted via http://www.ruby-forum.com/.