View Full Version : String.replace() (php syntax)

08-28-2009, 05:29 PM
AS2 doesn't have a replace function built into the String class, but this is the quickest solution I came up with. It doesn't accept regular expressions, just simple strings. I'm posting this to get feedback from scripting pros who like to optimize the hell out of things (as do I, I'm just being lazy atm); this method is using the String.split and Array.join which can be somewhat resource consuming so feel free to criticize/offer better solutions. Also, I used a functional solution rather than modifying the String's prototype for ease of understanding for newbies. A *.as (or root frame 1) prototype solution could likely perform more speedily.


function str_replace(search:String,replace:String,subject:String):String
return subject.split(search).join(replace);


var my_str:String = "Old Billy Bob Jones went down to the old store to buy some old cigarettes.";