How can I replace a string by range?
javascript, replace, string
Solution
function replaceRange(s, start, end, substitute) {
return s.substring(0, start) + substitute + s.substring(end);
}
var str = "this is a string";
var newString = replaceRange(str, 0, 4, "that"); // "that is a string"
Problem
I need to replace a string by range Example: ``` string = "this is a string";//I need to replace index 0 to 3 whith another string Ex.:"that" result = "that is a string"; ``` but this need to be dinamically. Cant be replace a fixed word ...need be by range I have tried ``` result = string.replaceAt(0, 'that'); ``` but this replace only the first character and I want the first to third