Reputation: 633
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?
Upvotes: 2
Views: 7605
Reputation: 1325
• .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" )
Upvotes: 6