Forum Moderators: open

Message Too Old, No Replies

Creating unicode character

         

RobBroekhuis

5:03 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



This one should be easy - if I have a numerical (or hexadecimal-string) representation of a unicode character, how do I create a string of that character?
For example, if I have variable
code=0xabcd
how do I create a string equivalent to
s='\uabcd'

In other words, I'm looking for the modern equivalent to Basic's old chr$() function :-)

Bernard Marx

5:51 pm on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of the few static methods in Javascript: String.fromCharCode

This creates a string from the args (charCodes) supplied.
The args can be in number or string form - with hex in the usual 0xabc format.


alert(String.fromCharCode(0x49,0x20,0x6c,0x69,0x6b,0x65,0x20,0x62,0x61,0x6e,0x61,0x6e,0x61,0x73));

RobBroekhuis

6:47 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Thanks much - just what I needed!