Reversing a String by Word or by Character : reverse « String « Flash / Flex / ActionScript






Reversing a String by Word or by Character

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var example:String = "hello dear reader";
        var words:Array = example.split( " " );
        words.reverse(  );
        
        var exampleRevByWord:String = words.join( " " );
        
        trace( exampleRevByWord );
        
        var characters:Array = example.split( "" );
        
        characters.reverse(  );
        
        var exampleRevByChar:String = characters.join( "" );
        
        trace( exampleRevByChar );
        
    }
  }
}

        








Related examples in the same category