# Searching for latin/umlaut characters in string

**URL:** <https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420>\
**Category:** Ruby\
**Created:** [May 1, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420 "2008-05-01T22:45:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 1, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/1 "2008-05-01T22:45:31Z")

</div>

Hi,

Ive read up a bit about uicode strings and the issues with rails after i  
tried to save some data which contained an umlaut character. I got the  
following error below when searching for a name that contained the  
character Ã©.

Unclosed quotation mark after the character string ')

Is there anyway to search a string for these types of characters and  
then ill decide what to do later??

Some sort of string method like scan or include??

JB

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 1, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/2 "2008-05-01T22:56:50Z")

</div>

On Thu, May 1, 2008 at 10:45 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Ive read up a bit about uicode strings and the issues with rails after i  
> tried to save some data which contained an umlaut character. I got the  
> following error below when searching for a name that contained the  
> character Ã©.
> 
> Unclosed quotation mark after the character string ')

Sounds like an encoding issue with the source code itself. Are you  
writing that “Ã©” in the program? If yes, is your editor configured to  
write UTF8?

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 10:17am UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/3 "2008-05-02T10:17:47Z")

</div>

Xavier N. wrote:

> On Thu, May 1, 2008 at 10:45 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Ive read up a bit about uicode strings and the issues with rails after i  
> > tried to save some data which contained an umlaut character. I got the  
> > following error below when searching for a name that contained the  
> > character Ã©.
> > 
> > Unclosed quotation mark after the character string ')
> 
> Sounds like an encoding issue with the source code itself. Are you  
> writing that “Ã©” in the program? If yes, is your editor configured to  
> write UTF8?

No the string is coming in via a csv file.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 11:19am UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/4 "2008-05-02T11:19:51Z")

</div>

John B. wrote:

> Xavier N. wrote:
> 
> > On Thu, May 1, 2008 at 10:45 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Ive read up a bit about uicode strings and the issues with rails after i  
> > > tried to save some data which contained an umlaut character. I got the  
> > > following error below when searching for a name that contained the  
> > > character Ã©.
> > > 
> > > Unclosed quotation mark after the character string ')
> > 
> > Sounds like an encoding issue with the source code itself. Are you  
> > writing that “Ã©” in the program? If yes, is your editor configured to  
> > write UTF8?
> 
> No the string is coming in via a csv file.

str = “My cafe\xcc\x81 is good.”  
puts str

if str.include?(“cafe\xcc\x81”)  
puts “yes”  
else  
puts “no”  
end

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/5 "2008-05-02T14:52:01Z")

</div>

Xavier N. wrote:

> On Fri, May 2, 2008 at 10:17 AM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Xavier N. wrote:
> > 
> > > Sounds like an encoding issue with the source code itself. Are you  
> > > writing that “Ã©” in the program? If yes, is your editor configured to  
> > > write UTF8?
> > 
> > No the string is coming in via a csv file.
> 
> Is the CSV file in UTF8?

Its Ansii as far as i can tell. Its actually coming from an excel  
spread sheet and the user then “saves as” comma separted csv. Then its  
import to the application wher i am running into the problem.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 11:53am UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/6 "2008-05-02T11:53:13Z")

</div>

On Fri, May 2, 2008 at 10:17 AM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Xavier N. wrote:
> 
> > Sounds like an encoding issue with the source code itself. Are you  
> > writing that “Ã©” in the program? If yes, is your editor configured to  
> > write UTF8?
> 
> No the string is coming in via a csv file.

Is the CSV file in UTF8?

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/7 "2008-05-02T15:22:25Z")

</div>

On Fri, May 2, 2008 at 2:52 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > No the string is coming in via a csv file.
> > 
> > Is the CSV file in UTF8?
> 
> Its Ansii as far as i can tell. Its actually coming from an excel  
> spread sheet and the user then “saves as” comma separted csv. Then its  
> import to the application wher i am running into the problem.

If the CSV is ANSII, and the Ruby source code is ANSII, where is the  
“Ã©” coming from? 🙂

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/8 "2008-05-02T16:38:27Z")

</div>

Xavier N. wrote:

> On Fri, May 2, 2008 at 2:52 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > > No the string is coming in via a csv file.
> > > 
> > > Is the CSV file in UTF8?
> > 
> > Its Ansii as far as i can tell. Its actually coming from an excel  
> > spread sheet and the user then “saves as” comma separted csv. Then its  
> > import to the application wher i am running into the problem.
> 
> If the CSV is ANSII, and the Ruby source code is ANSII, where is the  
> “Ã©” coming from? 🙂

Here is an example of the csv file with the word below and how it is  
displayed. They are identical. It looks like the file is utf-8 after  
all.

MÃ¼ller

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [May 2, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/searching-for-latin-umlaut-characters-in-string/136420/9 "2008-05-02T16:49:36Z")

</div>

On Fri, May 2, 2008 at 4:38 PM, John B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > spread sheet and the user then “saves as” comma separted csv. Then its  
> > > import to the application wher i am running into the problem.
> > 
> > If the CSV is ANSII, and the Ruby source code is ANSII, where is the  
> > “Ã©” coming from? 🙂
> 
> Here is an example of the csv file with the word below and how it is  
> displayed. They are identical. It looks like the file is utf-8 after  
> all.

No it is iso-8859-1. In that CSV “Ã¼” is a single byte instead of two:

fxn@feynman:~/tmp$ od -a testcsv.csv  
0000000 M ? l l e r cr nl  
0000010  
fxn@feynman:~/tmp$ od -a testcsv\_utf8.csv  
0000000 M ? ? l l e r  
0000007

You’d need to fetch data from the CSV, change its encoding in memory  
with iconv, and work with the result.

In general, when doing I/O like that you need to control every  
involved encoding to ensure everything matches.
