Gsub not working to replace a 'Chinese' Charater

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!

2010/1/28 Ryan S. [email protected]:

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

I found my mistake is using incorrect reg match, it works after change
to

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

thanks veryone!

On 28 jan 2010, at 17:59, Ryan S. 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
[email protected]