Getting Unicode Character Codes in JavaScript?
jargonCCNA asks: "I've searched high and low across the web, but I can't seem to be able to find any code snippets or even anything that'll help me out here. I'm trying to get a Unicode character code from a data stream in JavaScript and there doesn't seem to be anything out there to help me; JavaScript itself only has onboard support for ISO-Latin_1, or something. I tried hacking my own converter code, but it's rife with errors. Anybody know of some code that I can include in a GPL project?"
Just for reference -- I've seen a lot of people get nailed on Ask /. because they didn't do the proper research before asking their question. Google has failed me; I've been trying to figure this out on my own for about a month. I hope someone can shed some light on my situation."
"Here's the buggy code, if you're interested:
function unicode2hex( unicode )"Mozilla's JavaScript console lets me know that '\u0' is an illegal character. I think this would work if I could make it use the string "0000" instead of the number 0 for i.
{var hexString = "";}
for( var i = 0x0000; i <= 0xFFFF; i++ )
{test = eval( "\\u" + i );}
if ( unicode == test )
{hexString += i / 4096;}
hexString += i / 256;
hexString += i / 16;
hexString += i % 16;
hexString += "";
return hexString;
return false;
Just for reference -- I've seen a lot of people get nailed on Ask /. because they didn't do the proper research before asking their question. Google has failed me; I've been trying to figure this out on my own for about a month. I hope someone can shed some light on my situation."
How did this story get past the lameness filter?
Ask the Experts at http://selfforum.teamone.de. It's a german forum, but most people there can read and write english as well. The SelfForum is related to the famous SelfHTML (at least here in Germany, it is famous). Just copy and paste your question there.
Denken hilft.
What's the deal? Cliff must have hit the "Accept" instead of the "Reject" button by accident.
Try asking your question in IRC before hitting up "Ask Slashdot."
A search on google for unicode and javascript brings back a lot of positive looking results without actually delving into them. It seems like JS1.5 has support for this (from the Google summaries).
Marques Johansson
Ok, I got my "Second Post" in.. Now here's the good answer.
e /jsguide15/ident.html#1009690
document.write("\u00A9 Netscape Communications" );
I just did that in Galeon and it works fine...
See - http://developer.netscape.com/docs/manuals/js/cor
Marques Johansson
Why the hell did you let someone place this story under the topic JAVA?? JAVA != JAVASCRIPT. They're two completely different things. this story is a flat out troll.
Why don't you ask the Mozilla developers that are working on JavaScript 2.0?
Ouch! The truth hurts!
No offense, but I haven't used JS in years, and I found this in a matter of minutes.
document.write("\u00A9 is ");
document.write("\u00A9".charCodeAt(0));
That will give you the answer in decimal. I trust you can convert to hex yourself.
(Note: Requires Javascript 1.3; previous versions used ISO-Latin-1 rather than unicode, and I don't know what they'd do with a character higher than 255.)
The most valuable commodity I know of is information. - Michael Douglas as Gordon Gekko, Wall Street
Too bad there's no JavaScript topic, eh there chico?
Lick your own.
Matthew G P Coe
http://mgpcoe.blogspot.com/
Slashdot is a nerd website. We know better than to think JavaScript is at all Java. Change that Coffee Cup Graphic, bud.
How did this story get past the lameness filter?
Stories are probably not subject to the lameness filter (or at least they have looser filters) because an editor must approve each story by hand.
That said, I have a possible (untested) solution: Try changing each += in the inner loop to a +=""+ to force the strings to be concatenated rather than treated as numbers.
Will I retire or break 10K?