Pro*_*fer 1 javascript unicode unicode-string node.js
我有我的一篇文字
\n\nJapanese: \xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe4\xbd\xbf\xe7\x94\xa8\xe3\x81\x97\xe3\x81\xa6Quik\xe3\x83\x89\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\x96\xe3\x81\xab\xe3\x83\xad\xe3\x82\xb0\xe3\x82\xa4\xe3\x83\xb3\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82 \xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe8\xaa\xb0\xe3\x81\xa8\xe3\x82\x82\xe5\x85\xb1\xe6\x9c\x89\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84\xe3\x81\xa7\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84\n
Run Code Online (Sandbox Code Playgroud)\n\n我有它的unicode转换
\n\nUnicode: 3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044\n
Run Code Online (Sandbox Code Playgroud)\n\n这是我用一些在线工具完成的。现在我需要使用nodejs做同样的事情。
\n\n所以我的问题是 Unicode 类型是什么?如何将日语文本转换为 unicode?
\n\xe2\x80\xa2 .split("")
\xe2\x80\x94 将字符串从每个字符分离到数组中 // ["\xe3\x81\x93", "\xe3\x81\xae", "O" ...]\n
\ xe2\x80\xa2 循环到数组中,并将map()
每个字符替换为 charCode,转换为hex
字符串。
let str = "\xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe4\xbd\xbf\xe7\x94\xa8\xe3\x81\x97\xe3\x81\xa6Quik\xe3\x83\x89\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\x96\xe3\x81\xab\xe3\x83\xad\xe3\x82\xb0\xe3\x82\xa4\xe3\x83\xb3\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82 \xe3\x81\x93\xe3\x81\xaeOTP\xe3\x82\x92\xe8\xaa\xb0\xe3\x81\xa8\xe3\x82\x82\xe5\x85\xb1\xe6\x9c\x89\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84\xe3\x81\xa7\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84";\r\n\r\nstr = str.split("").map( char => addZeros( char.charCodeAt(0).toString(16) ) ).join("");\r\n\r\nfunction addZeros(str){ return ("0000" + str).slice(-4) }\r\n\r\n\r\nconsole.log( str );\r\n\r\n// for comparison\r\nconsole.log( "3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044" )
Run Code Online (Sandbox Code Playgroud)\r\n