1+ // Ch 4 String Practice Set
2+
3+ // Q1)Write a program that counts the number of characters in a given string.
4+
5+
6+
7+ // const str = "Hello, World!";
8+ // const count = str.length;
9+ // console.log(count); // Output: 13
10+
11+
12+ // Q2)Write a program that checks if a string contains a specific substring.
13+
14+
15+
16+ // const str = "Hello, World!";
17+ // const substring = "World";
18+ // const containsSubstring = str.includes(substring);
19+ // console.log(containsSubstring); // Output: true
20+
21+
22+
23+ // Q3)Write a program that converts a string to uppercase.
24+
25+
26+
27+ // const str = "Hello, World!";
28+ // const uppercaseStr = str.toUpperCase();
29+ // console.log(uppercaseStr); // Output: HELLO, WORLD!
30+
31+
32+
33+ // Q4)Write a program that extracts a portion of a string based on start and end indexes.
34+
35+
36+
37+ // const str = "Hello, World!";
38+ // const extractedStr = str.slice(7, 12);
39+ // console.log(extractedStr); // Output: World
40+
41+
42+ // Q5)Write a program that replaces a specific substring with another substring.
43+
44+
45+
46+ // const str = "Hello, John!";
47+ // const newStr = str.replace("John", "Alice");
48+ // console.log(newStr); // Output: Hello, Alice!
49+
50+
51+
52+ // Q6)Write a program that splits a string into an array of substrings based on a delimiter.
53+
54+
55+
56+ // const str = "Hello, World!";
57+ // const arr = str.split(",");
58+ // console.log(arr); // Output: ["Hello", " World!"]
59+
60+ // Q7)Write a program that checks if a string starts with a specific character or substring.
61+
62+
63+
64+ // const str = "Hello, World!";
65+ // const startsWithHello = str.startsWith("Hello");
66+ // console.log(startsWithHello); // Output: true
67+
68+
69+ // Q8)Write a program that checks if a string ends with a specific character or substring.
70+
71+
72+
73+ // const str = "Hello, World!";
74+ // const endsWithWorld = str.endsWith("World!");
75+ // console.log(endsWithWorld); // Output: true
76+
77+
78+ // Q9)Write a program that trims whitespace from the beginning and end of a string.
79+
80+
81+
82+ // const str = " Hello, World! ";
83+ // const trimmedStr = str.trim();
84+ // console.log(trimmedStr); // Output: Hello, World!
85+
86+
87+ // Q10)Write a program that checks if a string is empty.
88+
89+
90+
91+ // const str = "";
92+ // const isEmpty = str.length === 0;
93+ // console.log(isEmpty); // Output: true
0 commit comments