Please note the following is entirely under the assumption that you can't use built in functions which is stated by OP in comments
function Replace(s, strOld, strNew){
//find returns the starting index of the string you are looking for
// do some exception handling or return -1 if not there
var loc = find(s, strOld); //you should implement find
//assuming you can't use the slice function
retStr = "";
for(var i = 0; i < loc; i++){
retStr += s[i]; //builds new string with chars up to loc
}
retStr += strNew; //put the new string in
for(var i = loc + strOld.length; i < s.length; i++){
retStr += s[i]; //puts remaining chars from original string
}
return retStr;
}
Do something like this. I left the find function up to you but the rest is a pretty simple algorithm. Find should check s by character for matches with strOld that happen in a row.
Note: I changed the variable names from your original function. string to s because it's bad form to name a variable after a type. I changed the other two because they are misleading, since you are trying to replace a string not a char.
I'd also recommend you use ===
instead of ==
for equality until you understand what the difference is. See here for more