-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.4_Lab_StringOps.cs
55 lines (45 loc) · 1.14 KB
/
4.4_Lab_StringOps.cs
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
using System;
class String_Operations
{
static void read_input(string S)
{
int StrLen = S.Length;
int LastNum = StrLen - 1;
string LastStr = S.Substring(LastNum, 1);
if(LastStr == ".") {
Console.WriteLine("You have entered a declarative sentence.");
}
else if(LastStr == "?") {
Console.WriteLine("You have entered an interrogatory sentence.");
}
else if(LastStr == "!") {
Console.WriteLine("You have entered an exclamatory sentence.");
}
else {
Console.WriteLine("You did not enter a sentence.");
}
}
static void name(string fullName)
{
int x = fullName.IndexOf(" ");
if(x == -1) {
Console.WriteLine(fullName);
}
else {
int l = fullName.Length;
int L = l - x;
string lastName = fullName.Substring(x, L);
string firstName = fullName.Substring(0, x);
Console.WriteLine(lastName + ", " + firstName);
}
}
static void Main()
{
Console.Write("Enter a sentence with proper grammar: ");
string S = Console.ReadLine();
read_input(S);
Console.Write("Enter your first and last name or a name you go by: ");
string fullName = Console.ReadLine();
name(fullName);
}
}