Mic*_*jer 6 javascript unicode ascii transliteration
如何在纯 Javascript 中将 Unicode 字符音译为 ASCII?
\n\ninput: '\xc7\x8f\xc5\x84\xc5\xa5\xc4\x99\xc5\x99'\noutput: 'Inter'\nRun Code Online (Sandbox Code Playgroud)\n\n我需要与 shell 类似的效果iconv -f UTF-8 -t 'ASCII//TRANSLIT',但在普通 Javascript 中。
小智 0
使用有效替换字符串中所有重音字符的答案?像这样:
\n\nvar makeSortString = (function() {\n var translate_re = /[\xce\xb1\xce\xb2\xce\xb3]/g; // etc.\n var translate = {\n "\xce\xb1": "a", // alpha - a\n "\xce\xb2": "b", // beta -- b\n "\xce\xb3": "g" // gamma - g\n // etc.\n };\n return function(s) {\n return ( s.replace(translate_re, function(match) { \n return translate[match]; \n }) );\n }\n})();\nRun Code Online (Sandbox Code Playgroud)\n\n您可以扩展它以仅包含您想要的字符。
\n| 归档时间: |
|
| 查看次数: |
1650 次 |
| 最近记录: |