65.9K
CodeProject is changing. Read more.
Home

javascript replace() function replace only single characters

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (1 vote)

Oct 11, 2013

CPOL
viewsIcon

5310

javascript replace() function replace only single charactersI have been trying to use javascript replace() to search and replace special individual

javascript replace() function replace only single characters

I have been trying to use javascript replace() to search and replace special individual characters in a string. But having some difficulties.

We can use the following way to solve the following problem.

function ReplaceAllInstanceOfString(strString,strReplaceString,strReplaceByString)

{

       var intPos= strString .indexOf('+ strReplaceString +'); 

       if ( intPos !=-1)

       {  

               strString = strString .replace(/,/g,' + strReplaceByString + '); 

        }

        return strString ;

}