Hi
I have a string variable, e.g.
var s = "a string";
I wish to step through each character of the string, and carry out a computation on the ASCII value of the character. If I do the following:
for(var i=0; i<s.length; i++)
{
var n = s.charAt(i);
}
Then n correctly receives each character of the string, but unfortunately, I am unable to carry out any computations on n becase, I presume, it too is a string object.
If I was writing in 'C', I would put:
int n = (int)s[i];
How can I convert a character from a string into its numeric ASCII value?
Thanks
I have a string variable, e.g.
var s = "a string";
I wish to step through each character of the string, and carry out a computation on the ASCII value of the character. If I do the following:
for(var i=0; i<s.length; i++)
{
var n = s.charAt(i);
}
Then n correctly receives each character of the string, but unfortunately, I am unable to carry out any computations on n becase, I presume, it too is a string object.
If I was writing in 'C', I would put:
int n = (int)s[i];
How can I convert a character from a string into its numeric ASCII value?
Thanks
Comment