# What about charset?

**URL:** <https://www.ruby-forum.com/t/what-about-charset/188056>\
**Category:** Ruby\
**Created:** [May 5, 2010, 4:04am UTC](https://www.ruby-forum.com/t/what-about-charset/188056 "2010-05-05T04:04:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f07891/32.png) [@nax](https://www.ruby-forum.com/u/nax)\
**Post date:** [May 5, 2010, 4:04am UTC](https://www.ruby-forum.com/t/what-about-charset/188056/1 "2010-05-05T04:04:16Z")

</div>

Hi!

I have a ruby program wich take some information from a .txt file, and  
copy it to a sqlite3 table. But the text is in ASCII-8BIT charset, so  
when I select the data from the table, it doesn’t return the right  
characters. What can I do?

Thanks.

---

<div class="post-metadata">

**Author:** ![nax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f07891/32.png) [@nax](https://www.ruby-forum.com/u/nax)\
**Post date:** [May 5, 2010, 9:11pm UTC](https://www.ruby-forum.com/t/what-about-charset/188056/2 "2010-05-05T21:11:04Z")

</div>

NoÃ© Alejandro wrote:

> I have a ruby program wich take some information from a .txt file, and  
> copy it to a sqlite3 table. But the text is in ASCII-8BIT charset, so  
> when I select the data from the table, it doesn’t return the right  
> characters. What can I do?

Show your code, and also which exact versions of ruby, ruby-sqlite3 and  
operating system you are using.

Are you sure it doesn’t “return the right characters”? How do you know?  
Use str.bytes.to\_a to be sure, which will show you the actual byte  
codes, and compare this str.bytes.to\_a for the strings you put into the  
database.

Any data you put into sqlite3 should be returned the same. The string  
you get back from sqlite3 might be tagged with the wrong encoding (in  
ruby 1.9), but it should at least be the same string of bytes.  
Furthermore the encoding tag shouldn’t affect how they are displayed, at  
least if you’re using a regular “puts” to write them out, and haven’t  
started messing with external encoding settings.
