# Invalid byte sequence in UTF-8 , need to re-encode?

**URL:** <https://www.ruby-forum.com/t/invalid-byte-sequence-in-utf-8-need-to-re-encode/194452>\
**Category:** Rails\
**Created:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/invalid-byte-sequence-in-utf-8-need-to-re-encode/194452 "2010-09-06T16:39:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/invalid-byte-sequence-in-utf-8-need-to-re-encode/194452/1 "2010-09-06T16:39:29Z")

</div>

I have a string coming from an email body :  
(rdb:1) body  
“\r\nLe 3 sept. 2010 \340 19:06, Event Seve Test a \351crit :\r\n\r\n\>  
Please answer the question by writing an X at the chosen places :\r\n\>  
\r\n\> are you coming : \r\n\> \r\n\> YES: X\r\n\> \r\n\> NO:\_\r\n\> \r  
\n\> thanks for you answer\r\n\> \r\n\> the Seve Ballesteros”

when I want to resent this boy in another email, I get an error ,  
stating invalid byte sequence … sure the \r\n are causing the error

(rdb:1) sending\_confirmation\_email(@origin, @destination, @subject,  
@message)  
ArgumentError Exception: invalid byte sequence in UTF-8

should I strip them ? or is there any way to re-encode the string in  
UTF-8 ??? ( Ruby 1.8.3 and Ruby 1.9.2 )

thanks for your help

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 7, 2010, 2:46am UTC](https://www.ruby-forum.com/t/invalid-byte-sequence-in-utf-8-need-to-re-encode/194452/2 "2010-09-07T02:46:28Z")

</div>

Quoting E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> stating invalid byte sequence … sure the \r\n are causing the error
> 
> (rdb:1) sending\_confirmation\_email(@origin, @destination, @subject,  
> @message)  
> ArgumentError Exception: invalid byte sequence in UTF-8
> 
> should I strip them ? or is there any way to re-encode the string in  
> UTF-8 ??? ( Ruby 1.8.3 and Ruby 1.9.2 )

What is the original encoding? It doesn’t look like UTF-8. \r and \n  
are  
ASCII and so okay in UTF-8. It is the \340 and \351 that look  
suspicious.

Jeffrey
