PDA

View Full Version : ASCII CODE problem- a.s.a.p


solal
11-22-2002, 08:51 AM
How do I convert ASCII value into a letter/number/...
and the opposite?

in Pascal it's: ORD & CHR function, what are the functions in Javascript?

glenngv
11-22-2002, 08:56 AM
ascii = 65;
alert(String.fromCharCode(ascii));// gives A
str = "blah";
alert(str.charCodeAt(0)); //gives 98 which is the ascii code of b

beetle
11-22-2002, 03:15 PM
Glenn, I wonder, is there such a pair of functions for unicode?

A1ien51
11-22-2002, 07:30 PM
I was searching for the unicode thing too. I wish I could replace the page worth of code by a line or two. LOL

krycek
11-22-2002, 07:46 PM
Originally posted by beetle
Glenn, I wonder, is there such a pair of functions for unicode?

...those functions work just fine for me :D

they deal with codes up to 16-bit (0 through to 65535) and display all the relevant unicode sets.

so... what's the problem?

::] krycek [::

beetle
11-22-2002, 08:15 PM
What's the syntax you used? Like if I wanted to insert a tab from the string

"\u0009"

?

krycek
11-22-2002, 08:19 PM
String.fromCharCode seems to work fine.

like, String.fromCharCode(9)

I don't use this stuff just generally, I use it for my compression algorithms, but I do an output of the compressed string, and the chars are as expected. Like, some chinese and weird letters etc. And tabs work fine.

Try it! :)

::] krycek [::

beetle
11-22-2002, 08:33 PM
Ao, all the low-number unicode chars are identical to the ASCII version? In that case, you really aren't expressing them as unicode...are you?

krycek
11-22-2002, 08:40 PM
Originally posted by beetle
Ao, all the low-number unicode chars are identical to the ASCII version? In that case, you really aren't expressing them as unicode...are you?

as far as I know, yes you are.

unicodes 0 thru 127 are identical to ASCII (correct me if I am wrong)

hence u0009 = ascii 9

as I understand it, the point of unicode is to allow extra charsets to be used. those charsets start AFTER the default ASCII values have finished... otherwise, how would it all be compatible?

control chars have to remain the same, hence unicode 0-127 = ASCII :)

simple :)

::] krycek [::