-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.html
More file actions
46 lines (38 loc) · 1.3 KB
/
string.html
File metadata and controls
46 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Methods Example</title>
<script>
function demonstrateStringMethods() {
var originalString = "Hello, world!";
// Length of the string
var length = originalString.length;
// Convert to uppercase
var uppercaseString = originalString.toUpperCase();
// Convert to lowercase
var lowercaseString = originalString.toLowerCase();
// Find the index of a substring
var indexOfComma = originalString.indexOf(",");
// Replace a substring
var replacedString = originalString.replace("world", "Universe");
// Extract a substring
var extractedSubstring = originalString.slice(7, 12);
var output = "Original String: " + originalString +
"<br>Length: " + length +
"<br>Uppercase: " + uppercaseString +
"<br>Lowercase: " + lowercaseString +
"<br>Index of ',': " + indexOfComma +
"<br>Replaced: " + replacedString +
"<br>Extracted Substring: " + extractedSubstring;
document.getElementById("output").innerHTML = output;
}
</script>
</head>
<body>
<h1>JavaScript String Methods</h1>
<button onclick="demonstrateStringMethods()">Show String Methods</button>
<div id="output"></div>
</body>
</html>