View Full Version : Taking individual characters from a String

10-21-2003, 04:23 PM
Just wondering if anyone can help me do this... I think its possible but what I want to do is allow the user to input some text into a text box and then when they click on a button, the text is read one character at a time and changed depending on what that character is. the main part right now is just to get it to read individual characters.

I was thinking of putting the text from the input into a string but then I couldn't figure out how to access individual characters. I also tried an array but that just puts the entire text into one index so I dont know what I can do here. Any suggestions?


10-21-2003, 04:28 PM
charAt() ?

myString = "hello";
trace(myString.charAt(0)); // traces "h"
trace(myString.charAt(2)); // traces "l"

10-21-2003, 04:40 PM
put it into an array like this:

var txt="this is a test";
var ar=txt.split("");
trace(ar);//output: [t,h,i,s, ,i,s, ,a, ,t,e,s,t]

10-21-2003, 07:53 PM
Thanks senocular for your option there, unfortunately I've been unable to try it yet but I really want to.

Tg how would I access individual elements in the split after I have done like you said? again haven't had access to try this yet but will try both when I get the chance. Thanks for the help guys!


10-22-2003, 04:45 AM
u can easily get the character if u checked it in the test mode by
Debug>> list variables
u'd find

andso on, is this what u want??