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

9073d98d4031a4c07b2eac6b7bbada9b?d=identicon&s=25 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!
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 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
9073d98d4031a4c07b2eac6b7bbada9b?d=identicon&s=25 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!
A7324d7861fb40c96faa004ebf95dece?d=identicon&s=25 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
This topic is locked and can not be replied to.