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!
Advertisements
Brilliant, absolutely Brilliant… thanks
Thanks Man!!!
kool, really kool!
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;
}
cool man
Hey… very cool, but you got the parameters backward!
Thanx, very simple and helpful
Amazing.
thx man, but i think the parameter “replace” and “replace_with” are in the wrong position. CMIIW 😀
I just wonder why such a basic operation as replace substring by string is not implemented by default. 😦
Thankz………..
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
thankss,yaa parameter “replace” and “replace_with” are in wrong position
thanks for sharing mate!
cheers!
Thank u…………..simple and really helpful………
Thanks a ton ! Very nice and simple. Keep writing 🙂