将Javascript UTF-8转换为ASCII(例如PHP中的Iconv('UTF-8','ASCII//TRANSLIT',$ string))
我想知道如何使用Javascript将UTF-8中的字符转换"为最接近的ASCII等效字符,就像Iconv在PHP中一样.
I'm wondering how it's possible to 'translate' characters in UTF-8 to the closest ASCII equivalent using Javascript, just like Iconv doest in PHP.
示例:
ü变成u
ó变成o
ü becomes u
ó becomes o
我宁愿不使用替换,因为a)它需要一组完整的字符,这是很多工作,并且b)我将很难获得一组完整的字符,并且我会永远不确定我是否会错过一两个.
I'd rather not use a replace, because a) it requires a complete set of characters, which is a lot of work and b) i'd would be hard to get a complete set of characters, and i'll never be certain if i'm missing one or two.
正如@Pointy所说,您唯一的选择是根据字典来映射/替换字符.
As @Pointy said, your only option is to map/replace characters according to a dictionary.
You'll find this really useful: https://github.com/backbone-paginator/backbone.paginator/blob/a579796a30e583c4dfa09e0a86e4abd21e0b5b56/plugins/diacritic.js