Skip navigation
witherton
Currently Being Moderated

Tracing a string sequentially

May 20, 2012 7:26 AM

I am trying to write code that traces the individual letters of a string.

For instance, it would trace the word "high" as "h","i","g" and"h".

The closest I've gotten is this code:

 

var sampleword:String = "high";

for(var i:uint=0; i<sampleword.length;i++)

trace (sampleword.slice(i))

 

It traces the word high as "high", "igh", "gh" and "h".

I attempted to ad a second for loop with a higher value, but that did not achieve what I wanted:

 

var sampleword:String = "high";

for(var i:uint=0; i<sampleword.length;i++)

for(var j:uint=1; j=sampleword.length;i++)

trace (sampleword.slice([i,j]))

 

Any ideas as to what I'm doing wrong?

 
Replies
  • Currently Being Moderated
    May 20, 2012 7:34 AM   in reply to witherton

    Use:

     

    var sampleword:String = "high";

    for(var i:uint=0; i<sampleword.length;i++)

    trace (sampleword.charAt(i))

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2012 2:10 PM   in reply to witherton

    You're welcome.  You could have done it using the slice method, but that requires two arguments.  You should look it up in the help documentation if you want to resolve it still.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points