I have my one text
Japanese: このOTPを使用してQuikドライブにログインします。 このOTPを誰とも共有しないでください
I have its unicode conversion
Unicode: 3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044
This is I have done with some online tool. Now I need to do same thing using nodejs.
So my question is what is that type of Unicode? How can I convert it my Japanese text to unicode?
I have my one text
Japanese: このOTPを使用してQuikドライブにログインします。 このOTPを誰とも共有しないでください
I have its unicode conversion
Unicode: 3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044
This is I have done with some online tool. Now I need to do same thing using nodejs.
So my question is what is that type of Unicode? How can I convert it my Japanese text to unicode?
Share Improve this question asked Nov 25, 2019 at 6:18 ProferProfer 64310 gold badges47 silver badges97 bronze badges 5-
2
"このOTPを使用してQuikドライブにログインします。 このOTPを誰とも共有しないでください".split("").map(codepoint => codepoint.codePointAt(0).toString(16)).join("");
and yes, in this case,split
is exactly what you want, because it splits by codepoints, and not graphemes. – ASDFGerte Commented Nov 25, 2019 at 6:21 - It's the unicode code points of your string in base16 – Nick Parsons Commented Nov 25, 2019 at 6:23
- @ASDFGerte Well You can answer it as well – Profer Commented Nov 25, 2019 at 6:32
- There already is an adequate answer, saving me the effort to write one, thanks :) – ASDFGerte Commented Nov 25, 2019 at 6:42
- What do you want to do and why? To convert Unicode characters to numbers you have to use an encoding method like UTF-8, UTF-16, UTF-32 etc. Number values and number of bytes per character differ between encoding schemes so knowing the encoding used is needed to reverse the process. So what is the design objective here? – traktor Commented Nov 25, 2019 at 6:46
1 Answer
Reset to default 6• .split("")
— separate string into array from each character // ["こ", "の", "O" ...]
• loop into array with map()
and replace each character with charCode, converted to hex
string.
let str = "このOTPを使用してQuikドライブにログインします。 このOTPを誰とも共有しないでください";
str = str.split("").map( char => addZeros( char.charCodeAt(0).toString(16) ) ).join("");
function addZeros(str){ return ("0000" + str).slice(-4) }
console.log( str );
// for parison
console.log( "3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044" )
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742368257a4430751.html
评论列表(0条)