How to convert large UTF-8 strings into ASCII?

前端 未结 9 1702
盖世英雄少女心
盖世英雄少女心 2020-12-18 08:29

I need to convert large UTF-8 strings into ASCII. It should be reversible, and ideally a quick/lightweight algorithm.

How can I do this? I need the source

9条回答
  •  自闭症患者
    2020-12-18 09:12

    As others have said, you can't convert UTF-8 text/plain into ASCII text/plain without dropping data.

    You could convert UTF-8 text/plain into ASCII someother/format. For instance, HTML lets any character in UTF-8 be representing in an ASCII data file using character references.

    If we continue with that example, in JavaScript, charCodeAt could help with converting a string to a representation of it using HTML character references.

    Another approach is taken by URLs, and implemented in JS as encodeURIComponent.

提交回复
热议问题