I'm pretty stumped on this recursive function. I'm using it to highlight words in a text box, but it's giving me some strange output:
should be:
#define
testing #define
but instead it's:
testing #define
testing #define
here's the code
function replace_all( text, old_str, new_str ){
index_of = text.indexOf( old_str );
if( index_of != -1 ){
old_text = text.substring( 0, index_of );
new_text = text.substring( index_of + old_str.length );
new_text = replace_all( new_text, old_str, new_str );
text = old_text + new_str + new_text;
}
return text;
}
Any ideas on what's wrong with the function? It seems to be replacing all the old keywords with the last one found.
function replace_all(text,ostr,nstr) {return text.replace(new RegExp(ostr,"g"),nstr);}?replace_allfunction?