Skip to content

Commit 3ddd3c3

Browse files
committed
Add String methods example with replace functionality in HTML
1 parent 8e61492 commit 3ddd3c3

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<script>
10+
// length
11+
// character at the specified index
12+
// index of the first occurrence of a substring within the string
13+
// slice(start, end)
14+
// toUpperCase
15+
// toLowerCase
16+
// replace(searchValue, replaceValue)
17+
// split(separator, limit)
18+
19+
function replace_01(){
20+
21+
data = document.getElementById("t_data").value;
22+
old = document.getElementById("old").value;
23+
new_Data = document.getElementById("new_d").value;
24+
25+
26+
//new_data = data.replace(old, new_Data);
27+
new_data = data.replaceAll(old, new_Data);
28+
29+
document.getElementById("data_print").innerHTML = data;
30+
document.getElementById("New_print").innerHTML = new_data;
31+
32+
33+
34+
35+
}
36+
37+
38+
</script>
39+
40+
41+
<input type="text" id="t_data">
42+
<label>Old word</label> <input type="text" id="old">
43+
<label>new word</label> <input type="text" id="new_d">
44+
<button onclick="replace_01()">Replace</button>
45+
46+
<h1>Data : <span id="data_print"></span></h1>
47+
<h1>Update Data : <span id="New_print"></span></h1>
48+
49+
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)