Hi Jason.
Jason wrote:
This is a Chinese character in unicode: 挪
I made it in Javascript by adding "&#"+"25"+" 386"
I need to convert it in Javascript to this: 挪 (The actual character)
How do I achieve this conversion in Javascript?
挪 isn't the character in Unicode, it's the numeric character
entity in XML and HTML that means that character. 25386 is the Unicode
codepoint of that character. You can use the String.fromChar Code
function to create a string with a single character, given the codepoint.
If you have the codepoint, just pass it to the function. If you have
the string "挪", you need to extract the number from the string
and then pass it to the function. You can use something like:
function numericEntityTo Char(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/)[1]);
}
If you have a numeric character entity that uses hexadecimal, you'll
have to do it differently, e.g.:
function numericEntityTo Char(s) {
var xs = s.match(/^&#(x[0-9A-Fa-z]+);$/));
if (xs) {
return Number('0' + xs[1]);
}
return Number(s.match(/^&#(\d+);$/)[1]);
}
(Completely untested code, though.)
--
Cameron McCormack,
http://mcc.id.au/
xmpp:he****@jab ber.org â–ª ICQ 26955922 â–ª MSN
ca*@mcc.id.au