-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCh 4 String Practice Set.js
93 lines (42 loc) · 2.09 KB
/
Ch 4 String Practice Set.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Ch 4 String Practice Set
// Q1)Write a program that counts the number of characters in a given string.
// const str = "Hello, World!";
// const count = str.length;
// console.log(count); // Output: 13
// Q2)Write a program that checks if a string contains a specific substring.
// const str = "Hello, World!";
// const substring = "World";
// const containsSubstring = str.includes(substring);
// console.log(containsSubstring); // Output: true
// Q3)Write a program that converts a string to uppercase.
// const str = "Hello, World!";
// const uppercaseStr = str.toUpperCase();
// console.log(uppercaseStr); // Output: HELLO, WORLD!
// Q4)Write a program that extracts a portion of a string based on start and end indexes.
// const str = "Hello, World!";
// const extractedStr = str.slice(7, 12);
// console.log(extractedStr); // Output: World
// Q5)Write a program that replaces a specific substring with another substring.
// const str = "Hello, John!";
// const newStr = str.replace("John", "Alice");
// console.log(newStr); // Output: Hello, Alice!
// Q6)Write a program that splits a string into an array of substrings based on a delimiter.
// const str = "Hello, World!";
// const arr = str.split(",");
// console.log(arr); // Output: ["Hello", " World!"]
// Q7)Write a program that checks if a string starts with a specific character or substring.
// const str = "Hello, World!";
// const startsWithHello = str.startsWith("Hello");
// console.log(startsWithHello); // Output: true
// Q8)Write a program that checks if a string ends with a specific character or substring.
// const str = "Hello, World!";
// const endsWithWorld = str.endsWith("World!");
// console.log(endsWithWorld); // Output: true
// Q9)Write a program that trims whitespace from the beginning and end of a string.
// const str = " Hello, World! ";
// const trimmedStr = str.trim();
// console.log(trimmedStr); // Output: Hello, World!
// Q10)Write a program that checks if a string is empty.
// const str = "";
// const isEmpty = str.length === 0;
// console.log(isEmpty); // Output: true