How to Reverse a String


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var pString:String = "hello";
  2. var rString:String = "";
  3.  
  4. /*
  5. h e l l o
  6. 0 1 2 3 4 - position of the letter
  7. 1 2 3 4 5 - length of string
  8. - initial length is 5
  9. - substr("position of letter", "get one letter")
  10. */
  11.  
  12. for(var i:int = pString.length-1; i>=0; i--){
  13. rString += pString.substr(i,1);
  14. }
  15.  
  16. trace("String: " + pString);
  17.  
  18. trace("Reverse String: " + rString);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.