简体   繁体   中英

How can I convert string 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?

.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 comparison console.log( "3053306e004f0054005030924f7f752830573066005100750069006b30c930e930a430d6306b30ed30b030a430f33057307e3059300200203053306e004f0054005030928ab030683082517167093057306a30443067304f306030553044" )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM