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

R

Rk Ch

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!
 
A

Axel Etzold

Hi --
-------- Original-Nachricht --------
Datum: Wed, 30 Apr 2008 02:44:45 +0900
Von: Rk Ch <[email protected]>
An: (e-mail address removed)
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!

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
 
H

Harry Kakueki

Want to covert "Ruby$B%=!<%9%3!<%I40A42r@b(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!

Is this what you want to do?

$KCODE = "NONE"
str = "Ruby$B%=!<%9%3!<%I40A42r@b(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
 
D

Damjan Rems

Rk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top