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!
Datum: Wed, 30 Apr 2008 02:44:45 +0900
Von: Rk Ch <rollingwoods@gmail.com>
An: ruby-talk@ruby-lang.org
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
···
--
Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games!
$KCODE = "NONE"
str = "Rubyソースコード完全解説"
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
···
On Wed, Apr 30, 2008 at 2:44 AM, Rk Ch <rollingwoods@gmail.com> 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!
--
Posted via http://www.ruby-forum.com/\.
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)