String Manipulation Using replace() Method

This the series of JavaScript string manipulation. substring(), split(), charAt(), and now we play with replace() method.  replace() method used to replace specified sub string with other sub string. JavaScript replace() method is case sensitive.  For more detail I have two example, and the pattern of replace() method is:

stringObject.replace("pattern","replacement") 

pattern is specified sub string which will be replace (case sensitive).

replacement is other sub string which will replace the pattern.

1. The result of script below are same with original string object, because the string object doesn't contain sub string pattern.

   1: <script type="text/javascript">//<![CDATA[
   2:     var sObj ="String Manipulation Using split() Method";
   3:     alert( sObj.replace("Split","replace") );
   4: //]]></script>

The pattern is "Split" and string object doesn't contain this pattern, so the result is "String Manipulation Using split() Method".

2. The result of script bellow replace the original string object.

   1: <script type="text/javascript">//<![CDATA[
   2:     var sObj ="String Manipulation Using split() Method";
   3:     alert( sObj.replace("split","replace") );
   4: //]]></script>
The pattern is "split" and string object contain this pattern, so the result is "Manipulation Using replace() Method".