# Wanted: Script to convert to/from UTF-8/UTF-16/UTF-32

**URL:** <https://www.ruby-forum.com/t/wanted-script-to-convert-to-from-utf-8-utf-16-utf-32/147321>\
**Category:** Ruby\
**Created:** [August 31, 2008, 3:06am UTC](https://www.ruby-forum.com/t/wanted-script-to-convert-to-from-utf-8-utf-16-utf-32/147321 "2008-08-31T03:06:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siegfried\_Heintze](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Siegfried\_Heintze](https://www.ruby-forum.com/u/Siegfried_Heintze)\
**Post date:** [August 31, 2008, 3:06am UTC](https://www.ruby-forum.com/t/wanted-script-to-convert-to-from-utf-8-utf-16-utf-32/147321/1 "2008-08-31T03:06:01Z")

</div>

Does someone have a little ruby script that will read a file in  
UTF-8/UTF-16/UTF-32 (my choice) and search for all the characters  
between  
0x7f-0xffffff and convert them to an ASCII digit string that begins with  
“&#” and ends with “;” and output the whole thing? If not, could someone  
tell me how to write one?

How about a script to do the inverse?

Thanks!  
siegfried

---

<div class="post-metadata">

**Author:** ![Siegfried\_Heintze](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Siegfried\_Heintze](https://www.ruby-forum.com/u/Siegfried_Heintze)\
**Post date:** [August 31, 2008, 9:30am UTC](https://www.ruby-forum.com/t/wanted-script-to-convert-to-from-utf-8-utf-16-utf-32/147321/2 "2008-08-31T09:30:38Z")

</div>

you could just convert everything to it’s html entity form

[http://htmlentities.rubyforge.org/](http://htmlentities.rubyforge.org/)  
gem install -r htmlentities

+David

---

<div class="post-metadata">

**Author:** ![Siegfried\_Heintze](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Siegfried\_Heintze](https://www.ruby-forum.com/u/Siegfried_Heintze)\
**Post date:** [August 31, 2008, 6:57pm UTC](https://www.ruby-forum.com/t/wanted-script-to-convert-to-from-utf-8-utf-16-utf-32/147321/3 "2008-08-31T18:57:41Z")

</div>

Siegfried,

There is a wrapper library for the standard iconv that takes care of  
this stuff:

[http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html)

Take a look at:

[http://www.websideattractions.com/2007/10/24/ruby-script-to-convert-files-character-encoding/](http://www.websideattractions.com/2007/10/24/ruby-script-to-convert-files-character-encoding/)

Best regards,

–  
Aníbal Rojas

> **[Home - Has Many Developers](https://hasmanydevelopers.com/)**
>
> We are the best choice for your building design and development

> **[RUBYCORNER.COM](https://www.rubycorner.com/)**
>
> RUBYCORNER.COM - Contact us for any business inquiries

[http://removed\_email\_address@domain.invalid](http://removed_email_address@domain.invalid)
