
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>string 의 method 에 대해서 알아봅니다. -2</title>
<script type="text/javascript" src="js/03.js"></script>
</head>
<body>
<h2>
문자열.replace("기존문자열", "새로운문자열")
</h2>
<p id="replace_1"></p>
<p id="str"></p>
<p id="replace_2"></p>
<p id="replace_3"></p>
</body>
</html>
JS
window.onload = function() {
const str = "Please visit Microsoft! ORACLE / Microsoft MS-SQL";
let new_str = str.replace("Microsoft", "마이크로소프트");
document.getElementById("replace_1").innerHTML = new_str;
document.getElementById("str").innerHTML = str;
new_str = str.replace(/MICROSOFT/i, "마이크로소프트");
document.getElementById("replace_2").innerHTML = new_str;
new_str = str.replace(/MICROSOFT/gi, "마이크로소프트");
document.getElementById("replace_3").innerHTML = new_str;
}
정리
- 06_string
-> 03_string_method_2, 03.js