...

View Full Version : Print all the unicode characters



champion
08-22-2002, 05:11 AM
Hi,

I want to use Javascript to print out all the Unicode characters but I just failed to do so.

I know I need to do something like this




document.write("\uff1e");



But that is when my input is static. I want my input to be variable.

I.e,




for (i=0; i<65355; i++)
document.write(getHex(i));



But I just keep getting javacript error or it prints out "\uffef". I just don't know how to implement the getHex function.

Please help me.

Thanks and urgent.

joh6nn
08-22-2002, 07:53 AM
i came up with this, but it doesn't seem to work:

<script>
function getUnicode(num) {
num = num.toString(16);
if (num.length < 3) {
for ( var i = num.length; i < 4; i++) {
num = '0' + num;
}
}
return ( "\u" + num );
}

for ( var i = 0; i < 65355; i++) {
document.write(getUnicode(57));
}
</script>

i'm not sure you can do this with javascript. also, if you run a loop that large in javascript, your computer will choke.

champion
08-22-2002, 08:39 AM
brother,

that is the javascript error i encountered.

javascript reports a problem at your code for

return ( "\u" + num );

This is because "\u" expects a hexadecimal.

But when I put "\\u", it will just print out exactly the "\uxxxx" on my browser.

help! anyway, my computer will never choke because it is a super-computer!

joh6nn
08-22-2002, 09:19 AM
Originally posted by joh6nn
i'm not sure you can do this with javascript. ... your computer will choke.

Roy Sinclair
08-23-2002, 09:43 PM
This will work:



<script>
function getUnicode(num) {
num = num.toString(16);
if (num.length < 3) {
for ( var i = num.length; i < 4; i++) {
num = '0' + num;
}
}
return ( "&#" + num + ";" );
}

for ( var i = 0; i < 65355; i++) {
document.write(getUnicode(i));
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum