admin管理员组

文章数量:1325079

I'm trying to use a variable and \u to create an UTF character with Node.js.

var code = '0045';
console.log('\u0045', '\u' + code);

But the output bees

E u0045

How do I make it

E E

How do I create the character and store it in a variable?

I'm trying to use a variable and \u to create an UTF character with Node.js.

var code = '0045';
console.log('\u0045', '\u' + code);

But the output bees

E u0045

How do I make it

E E

How do I create the character and store it in a variable?

Share asked Mar 30, 2011 at 20:53 tirithentirithen 3,52711 gold badges43 silver badges67 bronze badges 1
  • 1 Why don't you use String.fromCharCode(n)? See developer.mozilla/en/JavaScript/Reference/Global_Objects/… – Elian Ebbing Commented Mar 30, 2011 at 20:59
Add a ment  | 

1 Answer 1

Reset to default 12

Use String.fromCharCode:

String.fromCharCode(0x0045)
String.fromCharCode(parseInt('0045', 16))

本文标签: utf 8How to create UTF characters dynamically with JavaScriptStack Overflow