Javascript for replacing n th character in a string

   
Javascript for replacing n th character in a string:
 
 
function RepalceCharacter(sourceString,stringTobeReplaced,index)
{
    var re = new RegExp('^(.{'+ –index +'}).(.*)$','');
    return sourceString.replace(re,'$1'+stringTobeReplaced+'$2');
};
 
//Test code 
alert( RepalceCharacter('nishanth','XSSSSX',3) ); 

6 comments

I bookmarked your post will read this latter

Regards

Wood

Hello admin, thnxx for sharing this article. I found it so cool. Cheers, Taj..

Nice work. Very informative article. I will love to bookmark you for the future preferences. Thanks for sharing.

Regards
Broadhurst

Success is not measured by what you accomplish but by the opposition you have encountered, and the courage with which you have maintained the struggle against overwhelming odds.

Leave a reply