Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
113 lines (71 loc) · 3.65 KB
/
Copy pathProgram.cs
File metadata and controls
113 lines (71 loc) · 3.65 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.ComponentModel.DataAnnotations;
namespace StringMethods
{
internal class Program
{
static void Main(string[] args)
{
string sampleString = "Hello, Beautiful world. I am ";
string inputString = string.Empty;
int sampleLength = sampleString.Length;
int imputLength = inputString.Length;
bool isEmpty = string.IsNullOrEmpty(inputString);
Console.Write($"String: \"{sampleString}\"");
Console.Write($" Number of characters: {sampleLength}");
Console.WriteLine($" Is string empty? {isEmpty}");
Console.Write($"String: \"{inputString}\"");
Console.Write($" Number of characters: {imputLength}");
Console.WriteLine($" Is string empty? {isEmpty}");
Console.Write("Please enter a letter to search for in the string: ");
char searchChar = Console.ReadKey().KeyChar;
int firstOccurrence = sampleString.IndexOf(searchChar);
if (firstOccurrence != -1)
{
Console.WriteLine($"\nThe first occurrence of '{searchChar}' is at index: {firstOccurrence}");
}
else
{
Console.WriteLine($"\nThe character '{searchChar}' was not found in the string.");
}
string upperCaseString = sampleString.ToUpper();
Console.WriteLine($"Uppercase version of the string: {upperCaseString}");
string lowerCaseString = sampleString.ToLower();
Console.WriteLine($"Lowercase version of the string: {lowerCaseString}");
string replacedString = sampleString.Replace("world", "universe");
Console.WriteLine("Replaced string: " + replacedString);
Console.Write("Enter your name: ");
Console.WriteLine("Concanated text: " + replacedString + Console.ReadLine());
string extractSubstring = sampleString.Substring(0, 5);
Console.WriteLine($"Extracted substring: {extractSubstring}");
bool startsWithHello = sampleString.StartsWith("Hello");
Console.WriteLine($"Does the string start with 'Hello'? {startsWithHello}");
bool endsWithPeriod = sampleString.EndsWith(".");
Console.WriteLine($"Does the string end with '.'? {endsWithPeriod}");
Console.Write("Enter a string to search for: ");
string searchString = Console.ReadLine();
bool containsSearchString = sampleString.Contains(searchString);
Console.WriteLine($"Does the string contain '{searchString}'? {containsSearchString}");
Console.Write("Enter your name: ");
string name = Console.ReadLine();
bool isNameInString = sampleString.Contains(name);
Console.WriteLine($"Is your name in the string? {isNameInString}");
int startIndex = sampleString.IndexOf("Beautiful");
if (startIndex != -1)
{
string extractedSubstring = sampleString.Substring(startIndex, "Beautiful".Length);
Console.WriteLine($"Copied word: {extractedSubstring}");
}
else
{
Console.WriteLine("The word 'Beautiful' was not found in the string.");
}
string[] wordsArray = sampleString.Split(' ');
foreach (string word in wordsArray)
{
Console.WriteLine($"{word} ({word.Length})");
}
string joinedString= String.Join(" ", wordsArray);
Console.WriteLine($"Joined string: {joinedString}");
}
}
}