1

When working with different languages, what is the proper way to sub a string out in Rails?

Example (Czech Translation):

str = "pro více informací"
replace = "<em>více</em>"
str["více"] = replace
puts str

The problem I keep running into (and this is for multiple languages, not just Czech) is the following: IndexError (string not matched)

Is there a better way to do a string replacement? I know about gsub and sub, but both methods cause the following errors

.gsub! and gsub errors: RegexpError (invalid multibyte character)

.sub! and .sub errors: RegexpError (invalid multibyte character)

4

1 回答 1

1

您将要浏览此线程。使用字节值进行替换。

于 2010-11-18T19:58:09.520 回答