charcodeat in IE

B

Bern

msdn docs say the String.charCodeAt method is supported by IE 5.5 and above.
I'm just curious that what do people use before IE 5.5 was released?
charCodeAt seems to be such an important method.
 
V

VK

myString.charAt(x).escape()
Gives you %FF formated ASCII code
Supported since LiteScript (> JavaScript 1.0)
Fails on Unicode of course, but there was not any that time :)
 
B

Bern

i thought the "escape" function should be used like this:

escape ("xxx...$%$")

anyway is there an alternative to charCodeAt that still works *now*?

the "escape" fucntion does not format alphanumeric chars.
 
V

VK

oops... sorry, I was thinking of the second part of the table (>128)... this
is what I had to deal with.

For the chars in the dead-zone (## 33 - 122 with breaks for some "escapable"
chars) we used preset arrays to compare with.

if (escape(c) == c) { // doesn't escape, x!o! :)
// then iterate throu the array
//
// yes, old times are not always good :)
//
// what is your biz, any way?
// maybe there is some better approach to your needs?
}
 
B

Bern

i got your idea.

var charcodes = new Array();
charcodes ['A'] = 65;
charcodes ['B'] = 66;
.....

anyway, i am doing a md5 calculation script.
Can imagine how huge an old md5 script will be...
 
V

VK

var charcodes = new Array();
charcodes ['A'] = 65;
charcodes ['B'] = 66;
....

I'm not sure you can init Array with char index values instead of integers,
but I may be just missing the train of progress :)

In our case it was:

var charcodes = new Array();
....
charcodes[65] = 'A';
charcodes[66] = 'B'
....
// and then:
if (escape(c) == c) {
for (i = 33; i <=122; i++) {
if (c == charcodes) {
// i contains the charcode
}
}
}
 
R

Randy Webb

VK said:
var charcodes = new Array();
charcodes ['A'] = 65;
charcodes ['B'] = 66;
....


I'm not sure you can init Array with char index values instead of integers,
but I may be just missing the train of progress :)

Yes, you can add them that way, but the length of the array stays 0.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 13 Oct
msdn docs say the String.charCodeAt method is supported by IE 5.5 and above.

I doubt whether they say that it is not available before IE5.5.
I'm just curious that what do people use before IE 5.5 was released?
charCodeAt seems to be such an important method.

It is in MS IE 4.0 as delivered with initial Win98.

Small Flanagan says it's ECMA-262 & JS 1.2.

It's in ECMA 15.5.4.5.
 
L

Lasse Reichstein Nielsen

VK said:
var charcodes = new Array();
charcodes ['A'] = 65;
charcodes ['B'] = 66;
....

I'm not sure you can init Array with char index values instead of integers,
but I may be just missing the train of progress :)

You can. It doesn't need to be an array, though. A simple Object would
suffice, since arrays are just special objects that have extra
functionality related to properties that have integers as names.
Also, in Javascript 'A' is not a "char", but a string.

/L
 
G

Grant Wagner

If you're going to do it that way, there is no need to define this stuff
manually:

var charcodes = new Object(); // or {}
// note object, not Array, you are going to be
// creating properties of an object, not members
// of an Array
var i = 91;
while (i-- > 65) { // Z to A
charcodes[String.fromCharCode(i)] = i;
}
i = 123;
while (i-- > 97) { // z to a
charcodes[String.fromCharCode(i)] = i;
}
// alternative to have all character codes from 255 to 0:
// var i = 256;
// while (i-- > 0) {
// charcodes[String.fromCharCode(i)] = i;
// }

for (var eachchar in charcodes) {
document.write(eachchar + ' = ' + charcodes[eachchar] + '<br>');
}

Since String#fromCharCode() has been available since Internet Explorer 4
(<url:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthfromcharcode.asp
/>), this should be fairly safe.

However, if you're only testing one or two characters one or two times, it
may be more efficient to just do:

if (myCharacter == String.fromCharCode(##)) { ...
i got your idea.

var charcodes = new Array();
charcodes ['A'] = 65;
charcodes ['B'] = 66;
....

anyway, i am doing a md5 calculation script.
Can imagine how huge an old md5 script will be...

VK said:
oops... sorry, I was thinking of the second part of the table (>128)... this
is what I had to deal with.

For the chars in the dead-zone (## 33 - 122 with breaks for some "escapable"
chars) we used preset arrays to compare with.

if (escape(c) == c) { // doesn't escape, x!o! :)
// then iterate throu the array
//
// yes, old times are not always good :)
//
// what is your biz, any way?
// maybe there is some better approach to your needs?
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,794
Members
47,342
Latest member
eixataze

Latest Threads

Top