JavaScript Reference/Javascript Methods/replace String

Материал из Web эксперт
Перейти к: навигация, поиск

"replace()" Example

   <source lang="javascript">
   

<html> <body> <button onclick="var myS = new String("Sample String");

                alert(myS.replace(/sam/i,"Text"));">REPLACE</button>

</body> </html>


     </source>
   
  


"replace()" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |String | +----------------+--------------------------------------------------------------+

     </source>
   
  


"replace()" Syntax, Parameters and Note

   <source lang="javascript">

Note: Searches the String using a regular expression and replaces matching content.

Syntax:

stringName.replace(param1, param2) Parameters:

   param1   Required; the regular expression.
   param2   Required; the string with which to replace matching content.
   
     
     </source>