String searchAndReplace()

one thing that i always thought was missing in the String class was a searchAndReplace function, and maybe there is one, but i have not heard about it at all, so i thought i’d make my own function.

since i didnt want to mess with the String class, i couldnt use String[dot]function(), so i have to reference the string as a parameter
plus, right after you reference the function, you have to say
[insert my string name here]=new_str

i still think its pretty okay, though

function searchAndReplace(oldchar:String, newchar:String, target:String) {
    new_str = "";
    for (i=0; i<target.length; i++) {
        if (target.charAt(i) == oldchar) {
            new_str += newchar;
        } else {
            new_str += target.charAt(i);
    target = new_str;
var my_string:String = "Replace every lower case E in this sentence with the letter 'a'";
searchAndReplace("e", "a", my_string);
Astring = new_str