[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Rk Ch

4/29/2008 5:45:00 PM

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-....

3 Answers

Axel Etzold

4/29/2008 6:35:00 PM

0

Hi --
-------- Original-Nachricht --------
> 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-....

maybe you can use the Uconv module from http://www.yoshidam.net...
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!
http://games.entertainment.gmx.net/de/entertainment/...

Harry Kakueki

4/30/2008 1:39:00 AM

0

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-....
>
>

Is this what you want to do?

$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

--
A Look into Japanese Ruby List in English
http://www.kakueki.com/ruby...

Damjan Rems

4/30/2008 6:45:00 AM

0

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
--
Posted via http://www.ruby-....