Wednesday, November 24, 2010

String reverse in flex : single line of code

Hi,
A tip to reverse a String without looping.we don't have direct reverse() method in String class. so to reverse the String we need to split the string and reverse it and then join it. the code is below.

var str:String = "flexing";
var reStr:String = str.split("").reverse().join("");
trace(reStr); //Output : gnixelf

split the String with null delimiter, reverse it and join with null delimiter again..
Happy Flexing....

1 comment:

  1. Thanks Dude very good example.Is der any option to remove space just like use of trim().

    ReplyDelete