# Ruby 1.9, CSV and encodings

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-csv-and-encodings/129426>\
**Category:** Ruby\
**Created:** [February 18, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/ruby-1-9-csv-and-encodings/129426 "2008-02-18T14:55:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrickreilly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b782af/32.png) [@patrickreilly](https://www.ruby-forum.com/u/patrickreilly)\
**Post date:** [February 18, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/ruby-1-9-csv-and-encodings/129426/1 "2008-02-18T14:55:39Z")

</div>

Hi,

I’d like to process an ISO-8859-1 encoded .csv file on a UTF-8 system  
using Ruby 1.9. The naive approach of using the CSV lib fails with  
“invalid mbstring sequence”. I don’t see where to specify the encoding.  
I’ve even tried the ‘–encoding’ command line switch, but it doesn’t  
seem to know ISO-8895-1 in all spellings I could come up with. (BTW,  
where is command line switch behavior like this documented in detail?)

Currently I’m reading the complete file, enforce the encoding and  
process the in-memory string:

file\_content = IO.readlines(file\_name).join  
file\_content.force\_encoding(‘ISO-8859-1’)  
parser = CSV.new(file\_content, …)

But that looks like a rather clumsy hack. What’s the “right” way to do  
it?

Thanks and best regards,  
Patrick
