Forum: Ruby on Rails Unicode problem with mb_chars.index

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Peter (Guest)
on 2008-12-15 14:57
(Received via mailing list)

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?


PS: I am using ruby 1.8.6 on linux with rails 2.2.2
Peter (Guest)
on 2008-12-19 10:17
(Received via mailing list)
I found a workaround for this:
last = str.mb_chars.length - 1
str.mb_chars[from_index, last].index("a") + from_index
This topic is locked and can not be replied to.