Vaibhav B. wrote:
Hum, it depends on your context. If you don’t know anything about the
string and must make a guess, charguess or chardet are good tools.
Note that if you simply want to filter out content which can’t be utf-8
the following can be used,
utf8_ok = true
# will raise an error (Iconv::InvalidSequence from memory)
# on invalid utf-8 content
Iconv.iconv(utf-8, utf-8, self)
utf8_ok = false
I use a slighty more complex version where I cache an Iconv instance.
This helped solve my UTF-8 problems with one of my databases.