Click to See Complete Forum and Search --> : JavaScript string and chartAt()


Kvang
07-24-2003, 01:09 AM
For example this is a string -> "ABCDE..."

How can you get the characters that are at even posistion for exmple again I wanted to get only the even position character like "A", "C", "E" only in the string "ABCDE...".

Also I wanted to get the character at position for example again once if I got the character A on the 0 position and wanted to skip the other 2 characters and go directly for the other character in the third position like "D" and I wanted to skip both "B" and "C" character. Because I try the for loop to try to do that ,but it doesn't work because if I put in for(var i=0;i<this.length;i+=2)
{
nstring+=this string.charAt(i);
}

And I get AABBC... as a result.

Thanks for your help.

pelegk1
07-24-2003, 02:09 AM
string="abcdef";
for(var i=0;i<string.length;i+=2)
{ alert(string.charAt(i));}

-->> ace

Gollum
07-24-2003, 02:16 AM
I can't see what is wrong.
Could you post more code? Or a link?

Kvang
07-24-2003, 03:12 PM
Thank pelegk1 and many other who replies to my post or question. It probably my mistake then.

Khalid Ali
07-24-2003, 05:31 PM
Originally posted by Kvang
For example this is a string -> "ABCDE..."

.........i<this.length;i+=2)


this.length is wrong it should have been
any other valid variable name...

just so that you know what was wrong with it...
:D