fastest find and replace


flash.jpg Well I don't guarentee that this code is the fastest, but for me this is the fastest

function findreplace(str, find, replace) {
var replace_arr:Array = str.split(find);
var replaced_str:String = replace_arr.join(replace);
return replaced_str;
}
var temp_str:String = "vinodvv aka fxtreme";
var find_str:String = "fxtreme";
var replace_str:String = "vcube";
var result_str:String = findreplace(temp_str,find_str,replace_str);
trace(result_str); // expected result -"vinodvv aka vcube"

var temp_str:String = "vinodvvakafxtreme";
var find_str:String = "fxtreme";
var replace_str:String = "vcube";
var result_str:String = findreplace(temp_str,find_str,replace_str);
trace(result_str);// expected result -"vinodvvakavcube"

ascode.jpg

I guess I don't have to explain line by line, BTW you can even use the same function in javascript. here is the script

codejs.jpg
Feel free to add other fastest code if you have one…. 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s