Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  195] [ 5]  / answers: 1 / hits: 19798  / 12 Years ago, mon, september 24, 2012, 12:00:00

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


More From » string

 Answers
2
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

[#82934] Friday, September 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marisela

Total Points: 103
Total Questions: 105
Total Answers: 102

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;