How to convert "ソー" into "\343\202\275\343\203\274"?

Want to covert “Rubyソースコード完全解説” into
“Ruby\343\202\275\343\203\274\343\202\271\343\202\263\343\203\274\343\203\211\345\256\214\345\205\250\350\247\243\350\252\254”.
To solve fxruby displaying asia string.
Any method?
Thanks a lot!

Hi –
-------- Original-Nachricht --------

Datum: Wed, 30 Apr 2008 02:44:45 +0900
Von: Rk Ch [email protected]
An: [email protected]
Betreff: How to convert “ソー” into “\343\202\275\343\203\274”?

Want to covert “Rubyソースコード完全解説” into
“Ruby\343\202\275\343\203\274\343\202\271\343\202\263\343\203\274\343\203\211\345\256\214\345\205\250\350\247\243\350\252\254”.
To solve fxruby displaying asia string.
Any method?
Thanks a lot!

Posted via http://www.ruby-forum.com/.

maybe you can use the Uconv module from
http://www.yoshidam.net/Ruby.html
There are several encodings for Japanese signs, so you may have to try a
bit …

Best regards,

Axel

On Wed, Apr 30, 2008 at 2:44 AM, Rk Ch [email protected] wrote:

Want to covert “Rubye$B%=!<%9%3!<%I40A42r@be(B” into
“Ruby\343\202\275\343\203\274\343\202\271\343\202\263\343\203\274\343\203\211\345\256\214\345\205\250\350\247\243\350\252\254”.
To solve fxruby displaying asia string.
Any method?
Thanks a lot!

Posted via http://www.ruby-forum.com/.

Is this what you want to do?

$KCODE = “NONE”
str = “Rubye$B%=!<%9%3!<%I40A42r@be(B”
p str #
Ruby\343\202\275\343\203\274\343\202\271\343\202\263\343\203\274\343\203\211\345\256\214\345\205\250\350\247\243\350\252\254

Harry

Rk Ch wrote:

Want to covert “Rubyソースコード完全解説” into
“Ruby\343\202\275\343\203\274\343\202\271\343\202\263\343\203\274\343\203\211\345\256\214\345\205\250\350\247\243\350\252\254”.
To solve fxruby displaying asia string.
Any method?
Thanks a lot!

This is how I do it. I guess it
########################################################################

konvert_1250_UTF

#########################################################################
def konvert_1250_UTF(st)
r = ‘’
st.each_byte do |b|
r << case b
when 0…137: b.chr
when 138: 'Å ’
when 142: ‘Ž’
when 154: ‘Å¡’
when 158: ‘ž’
when 198: ‘Ć’
when 200: ‘ÄŒ’
when 208: ‘Ä‘’
when 230: ‘ć’
when 232: ‘č’
when 240: ‘Đ’
else b.chr
end
end
r
end

#########################################################################

konvert_UTF_1250

#########################################################################
def konvert_UTF_1250(st)
=begin

slowest way

r = ‘’
st.each_char do |c|
r << case c

when ’ '…‘z’: b.chr # faster if not used

 when 'Å ': 138.chr
 when 'Ž': 142.chr
 when 'Å¡': 154.chr
 when 'ž': 158.chr
 when 'Ć': 198.chr
 when 'Č': 200.chr
 when 'Ä‘': 208.chr
 when 'ć': 230.chr
 when 'č': 232.chr
 when 'Đ': 240.chr
 else c
end

end
r

Faster. At least for 10 chars

st.gsub!('Å ', 138.chr)
st.gsub!(‘Ž’, 142.chr)
st.gsub!(‘Å¡’, 154.chr)
st.gsub!(‘ž’, 158.chr)
st.gsub!(‘Ć’, 198.chr)
st.gsub!(‘ÄŒ’, 200.chr)
st.gsub!(‘Ä‘’, 208.chr)
st.gsub!(‘ć’, 230.chr)
st.gsub!(‘č’, 232.chr)
st.gsub(‘Đ’, 240.chr)
=end

This is about 3 times faster as previous

  st.gsub!(/Å /, 138.chr)
  st.gsub!(/Ž/, 142.chr)
  st.gsub!(/Å¡/, 154.chr)
  st.gsub!(/ž/, 158.chr)
  st.gsub!(/Ć/, 198.chr)
  st.gsub!(/Č/, 200.chr)
  st.gsub!(/Ä‘/, 208.chr)
  st.gsub!(/ć/, 230.chr)
  st.gsub!(/č/, 232.chr)
  st.gsub(/Đ/, 240.chr)

end

by
TheR