# Unicode problem with mb\_chars.index

**URL:** <https://www.ruby-forum.com/t/unicode-problem-with-mb-chars-index/155671>\
**Category:** Rails\
**Created:** [December 15, 2008, 1:57pm UTC](https://www.ruby-forum.com/t/unicode-problem-with-mb-chars-index/155671 "2008-12-15T13:57:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [December 15, 2008, 1:57pm UTC](https://www.ruby-forum.com/t/unicode-problem-with-mb-chars-index/155671/1 "2008-12-15T13:57:45Z")

</div>

Hello,

I tried the following  
str =“ÄÄa\_\_”  
assert str.mb\_chars.is\_utf8?  
assert str.is\_utf8?

# this is logical

assert\_equal 4, str.index(“a”, 4)

# this is not logical. shouldn’t this be nil !?

assert\_equal 2, str.mb\_chars.index(“a”, 4)

Why is the last line failing? And how could I fix this?

Regards,  
Peter.

PS: I am using ruby 1.8.6 on linux with rails 2.2.2

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [December 19, 2008, 9:17am UTC](https://www.ruby-forum.com/t/unicode-problem-with-mb-chars-index/155671/2 "2008-12-19T09:17:00Z")

</div>

I found a workaround for this:  
last = str.mb\_chars.length - 1  
str.mb\_chars[from\_index, last].index(“a”) + from\_index
