# Convert a string to utf8

**URL:** <https://www.ruby-forum.com/t/convert-a-string-to-utf8/86083>\
**Category:** Rails\
**Created:** [February 19, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/convert-a-string-to-utf8/86083 "2007-02-19T19:10:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jotape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@jotape](https://www.ruby-forum.com/u/jotape)\
**Post date:** [February 19, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/convert-a-string-to-utf8/86083/1 "2007-02-19T19:10:42Z")

</div>

Hello.

I’m reading a csv file into my application, and when I enconter a  
special character like Ã§, I have a problem, since my database is in  
utf-8. Is there a way to convert a string to utf-8?

---

<div class="post-metadata">

**Author:** ![jotape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@jotape](https://www.ruby-forum.com/u/jotape)\
**Post date:** [February 19, 2007, 7:17pm UTC](https://www.ruby-forum.com/t/convert-a-string-to-utf8/86083/2 "2007-02-19T19:17:17Z")

</div>

Pedro C. wrote:

> Hello.
> 
> I’m reading a csv file into my application, and when I enconter a  
> special character like Ã§, I have a problem, since my database is in  
> utf-8. Is there a way to convert a string to utf-8?

OK. Found it myself 😛

For someone loking for the same thing …

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

---

<div class="post-metadata">

**Author:** ![jotape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@jotape](https://www.ruby-forum.com/u/jotape)\
**Post date:** [February 19, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/convert-a-string-to-utf8/86083/3 "2007-02-19T19:32:34Z")

</div>

On Feb 19, 2007, at 7:10 PM, Pedro C. wrote:

> I’m reading a csv file into my application, and when I enconter a  
> special character like ç, I have a problem, since my database is in  
> utf-8. Is there a way to convert a string to utf-8?

Yes, use iconv. You’ll need to know the input character encoding, or  
give

[http://raa.ruby-lang.org/project/charguess/](http://raa.ruby-lang.org/project/charguess/)

a try otherwise.

– fxn
