I have a string, let\'s say Hello world
and I need to replace the char at index 3. How can I replace a char by specifying a index?
var str = \"h
@CemKalyoncu: Thanks for the great answer!
I also adapted it slightly to make it more like the Array.splice method (and took @Ates' note into consideration):
spliceString=function(string, index, numToDelete, char) {
return string.substr(0, index) + char + string.substr(index+numToDelete);
}
var myString="hello world!";
spliceString(myString,myString.lastIndexOf('l'),2,'mhole'); // "hello wormhole!"