Flex str_replace function

After scouring Google for hours trying to find some easy string replacement function in AS3, I ran across this.


private function str_replace( replace_with:String, replace:String, original:String ):String
{
var array:Array = original.split(replace_with);
return array.join(replace);
}

As you can see, it’s quite simple. You provide three things, replace_with – the new text, replace – what you want to replac, and the original string.

Just thought I’d share that!

12 Responses

  1. Brilliant, absolutely Brilliant… thanks

  2. Thanks Man!!!
    kool, really kool!

  3. use the replace method on the String object

    public function MyXMLEncode(str:String):String {
    /** /g at the end will replaceAll */
    str = str.replace(/’/g, “'”);
    return str;
    }

  4. cool man

  5. Hey… very cool, but you got the parameters backward!

  6. Thanx, very simple and helpful

  7. Amazing.

  8. thx man, but i think the parameter “replace” and “replace_with” are in the wrong position. CMIIW :D

  9. I just wonder why such a basic operation as replace substring by string is not implemented by default. :-(

  10. Thankz………..

  11. thanks a bunch.
    i have to develop an app which can search & replace a string across multiple files given a root directory.can you suggest me of how to do that?
    -RK

  12. thankss,yaa parameter “replace” and “replace_with” are in wrong position

Leave a Reply