# Autodetect encoding / mojibake correction?

**URL:** <https://www.ruby-forum.com/t/autodetect-encoding-mojibake-correction/73491>\
**Category:** Ruby\
**Created:** [October 24, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/autodetect-encoding-mojibake-correction/73491 "2006-10-24T22:14:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![capeboylego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e4f/32.png) [@capeboylego](https://www.ruby-forum.com/u/capeboylego)\
**Post date:** [October 24, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/autodetect-encoding-mojibake-correction/73491/1 "2006-10-24T22:14:01Z")

</div>

Hi,  
Is there something to automatically detect what encoding a file is? That  
way, I don’t have to guess when using iconv.  
Also, is there a script/gem/etc that can correct mojibake? If not, I  
want  
to write it… though I’m not quite sure how…

Thanks,  
Cameron

---

<div class="post-metadata">

**Author:** ![capeboylego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e4f/32.png) [@capeboylego](https://www.ruby-forum.com/u/capeboylego)\
**Post date:** [October 25, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/autodetect-encoding-mojibake-correction/73491/2 "2006-10-25T12:05:23Z")

</div>

Hi,

On Wed, 25 Oct 2006 05:12:53 +0900, Cameron A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,  
> Is there something to automatically detect what encoding a file is? That  
> way, I don’t have to guess when using iconv.  
> Also, is there a script/gem/etc that can correct mojibake? If not, I want  
> to write it… though I’m not quite sure how…

Check our NKF and Kconv in Ruby’s standard lib.

NKF.guess can be used for detecting some encodings.  
There is also the Kconv lib for making some encoding conversions.

I hope that helps,

Zev
