Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print all the unicode characters

    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.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    Originally posted by joh6nn
    i'm not sure you can do this with javascript. ... your computer will choke.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This will work:

    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •