Groups | Blog | Home
all groups > flash actionscript > february 2007 >

flash actionscript : Subtracting 2 characters(Flash MX)


thunder_storm
2/5/2007 8:31:19 PM
Hi guys,
I am trying to subtract 2 characters in action script, My code line looks like
this : temp=Number(str.charAt(j)-'A');
trace(temp);
But everytime i run the command i get NaN as the O/P, such a command works
fine in C, what to do to get this working in actionscript?
Manno Bult
2/5/2007 9:38:48 PM
Hi,

What does such a thing yield in C?
Does it substract ASCII codes?
Then I would look into the charCodeAt() and fromCharCode() methods.

trace("C" - "A");
also gives NaN, so converting it to a Number doesn't do much better :)

HTH,
Manno

[quoted text, click to view]

--
----------
Manno Bult
http://www.aloft.nl
thunder_storm
2/5/2007 9:55:46 PM
Such a code in C wud yield the difference between the postition of the two
chars in the string array.. eg. str='abcd..'
so b-c = 1 .. i m not checking this so i may be wrong but from past exp i
think its what we get..
It does not subtract the ascii codes... i know abt the charCode() .. i wud
like to know if there is a way i can get the difference in the position of the
2 chars..
Manno Bult
2/5/2007 11:02:54 PM
Ah!...

then the indexOf() (together with Math.abs()) method would do:

"abcd".indexOf("b") == 1
"abcd".indexOf("d") == 3

str = "abcd";
str.indexOf("b") - str.indexOf("d") == -2 (Math.abs(-2) == 2)

Manno

[quoted text, click to view]

--
----------
Manno Bult
http://www.aloft.nl
AddThis Social Bookmark Button