-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (42 loc) · 1.96 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (42 loc) · 1.96 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
class StringMethods
{
class Program
{
static void Main(string[] args)
{
string fullName = "John Doe";
// Convert to uppercase
string upperCaseName = fullName.ToUpper();
// Convert to lowercase
string lowerCaseName = fullName.ToLower();
// Check if the string contains a substring
bool containsJohn = fullName.Contains("John");
// Find the index of a substring
int indexOfDoe = fullName.IndexOf("Doe");
// Split the string into an array
string[] nameParts = fullName.Split(' ');
// Replace a substring with another substring
string replacedName = fullName.Replace("Doe", "Smith");
// Trim whitespace from the start and end of the string
string trimmedName = fullName.Trim();
// Check if the string starts with a specific substring
bool startsWithJohn = fullName.StartsWith("John");
// Check if the string ends with a specific substring
bool endsWithDoe = fullName.EndsWith("Doe");
// Get the length of the string
int nameLength = fullName.Length;
// Print the results
Console.WriteLine("Original Name: " + fullName);
Console.WriteLine("Uppercase: " + upperCaseName);
Console.WriteLine("Lowercase: " + lowerCaseName);
Console.WriteLine("Contains 'John': " + containsJohn);
Console.WriteLine("Index of 'Doe': " + indexOfDoe);
Console.WriteLine("Name Parts: " + string.Join(", ", nameParts));
Console.WriteLine("Replaced Name: " + replacedName);
Console.WriteLine("Trimmed Name: " + trimmedName);
Console.WriteLine("Starts with 'John': " + startsWithJohn);
Console.WriteLine("Ends with 'Doe': " + endsWithDoe);
Console.WriteLine("Name Length: " + nameLength);
}
}
}