Forum: Rails I18n gsub not working to replace a 'Chinese' Charater.

Posted by Ryan Smith (sunraise2005)
on 2010-01-28 17:59
gsub not works for me when replace 'DBCS'(double byte character set)
character,  using last version ruby 1.8.6

when "str汉字end".gsub(/汉字/,"hanzi"),
   output still is: str汉字end , but not strhanziend which I want to get.

Searched web two whole night with no clue found.

Anyone can help are much appreciated, need got it work very urgent.
thank you!
Posted by Henrik --- (malesca)
on 2010-01-29 01:16
(Received via mailing list)
2010/1/28 Ryan Smith <lists@ruby-forum.com>:
> gsub not works for me when replace 'DBCS'(double byte character set)
> character,  using last version ruby 1.8.6
>
> when "strºº×Öend".gsub(/ºº×Ö/,"hanzi"),
>   output still is: strºº×Öend , but not strhanziend which I want to get.
>
> Searched web two whole night with no clue found.
>
> Anyone can help are much appreciated, need got it work very urgent.
> thank you!

Works for me with ruby 1.8.7 (2008-08-11 patchlevel 72) 
[universal-darwin10.0]
 and ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]:

    puts "strºº×Öend".gsub(/ºº×Ö/,"hanzi")

outputs

    strhanziend
Posted by Ryan Smith (sunraise2005)
on 2010-01-29 06:13
I found my mistake is using incorrect reg match, it works after change 
to

s=s.gsub(/#{cnarray[i]}/, x.to_s)

thanks veryone!
Posted by Julik Tarkhanov (Guest)
on 2010-01-29 17:03
(Received via mailing list)
On 28 jan 2010, at 17:59, Ryan Smith wrote:

> Anyone can help are much appreciated, need got it work very urgent.
> thank you!



bigbuk:~ julik$ cat hanzi.rb
$KCODE = "u"
puts "strºº×Öend".gsub(/ºº×Ö/,"hanzi")

bigbuk:~ julik$ ruby hanzi.rb
strhanziend

I think you have some normalization problem which disappeared as soon
as you pasted your CJK into the email
--
Julik Tarkhanov
me@julik.nl
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.