JavaScript Tutorial/String/replace

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

String.replace()

Syntax



string.replace(regexpression, replacestring)


Using the replace() method of the String object

<html>
<head>
<title>Using the replace() method of the String object</title>
<script type="text/javascript" language="javascript">
<!-- //
var originalString = "A ab abc abcd";
var replacedString = "a";
var replacementString = "z";
var newString = originalString.replace(replacedString, replacementString);
document.write("<h3>" + newString + "</h3");
// -->
</script>
</head>
<body>
</body>
</html>