Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

javascript replace() function replace only single characters

0.00/5 (No votes)
8 Jul 2012 1  
javascript replace() function replace only single charactersI have been trying to use javascript replace() to search and replace special individual

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

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 ;

}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here