function myReplace(str, before, after) {
var test = '/'+ before +'/';
//return after;
if(before[0] == before[0].toUpperCase()){
var firstLetter = after.split('').splice(0,1);
var restOfTheWord = after.split('').splice(1,after.length).join('');
after = firstLetter[0].toUpperCase()+restOfTheWord;
}
var newstr = str.split(before).join(after);
return newstr;
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
No comments:
Post a Comment