# How to convert "ã‚½ãƒ¼" into "\\343\\202\\275\\343\\203\\274"?

**URL:** <https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202>\
**Category:** Ruby\
**Created:** [April 29, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202 "2008-04-29T19:44:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [April 29, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202/1 "2008-04-29T19:44:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [April 29, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202/2 "2008-04-29T20:36:13Z")

</div>

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

> Datum: Wed, 30 Apr 2008 02:44:45 +0900  
> Von: Rk Ch [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> 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/](http://www.ruby-forum.com/).

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

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [April 30, 2008, 3:40am UTC](https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202/3 "2008-04-30T03:40:16Z")

</div>

On Wed, Apr 30, 2008 at 2:44 AM, Rk Ch [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](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

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [April 30, 2008, 8:45am UTC](https://www.ruby-forum.com/t/how-to-convert-a-a-into-343-202-275-343-203-274/136202/4 "2008-04-30T08:45:14Z")

</div>

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
