-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringView.cs
More file actions
162 lines (147 loc) · 5.2 KB
/
StringView.cs
File metadata and controls
162 lines (147 loc) · 5.2 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using Jayroni.Services;
namespace Jayroni.Views
{
public class StringView
{
private string stringService;
public StringView()
{
stringService = new StringService();
}
public void showMenu()
{
while(true)
{
Console.WriteLine("---BSCS INTERNETAN PROCESSING SYSTEM---");
Console.WriteLine("1. Enter text.");
Console.WriteLine("2. View Current text.");
Console.WriteLine("3. Convert to upper case.");
Console.WriteLine("4. Convert to lower case");
Console.WriteLine("5. Count Characters.");
Console.WriteLine("6. Check if contains words.");
Console.WriteLine("7. Replace word.");
Console.WriteLine("8. Extract substring.");
Console.WriteLine("9. Trim spaces. ");
Console.WriteLine("10. Reset text.");
Console.WriteLine("11. Exit");
Console.WriteLine("Choose an option: ");
string choice = Console.ReadLine();
switch(choice)
{
case "1":
EnterText();
break;
case "2":
ViewCurrentText();
break;
case "3":
ConvertToUpper();
break;
case "4":
ConvertToLower();
break;
case "5":
CountCharacters();
break;
case "6":
CheckIfContainsWord();
break
case "7":
ReplaceWord();
break;
case "8":
ExtractSubstring();
break;
case "9":
TrimSpaces();
break
case "10":
ResetText();
break
case "11":
Exit();
return;
default:
Console.WriteLine("!!!INVALID OPTION!!! PLEASE TRY AGAIN!!");
break;
}
}
}
private void EnterText()
{
Console.WriteLine("Enter text: ");
string text = Console.ReadLine();
stringService.setText(text);
Console.WriteLine("Text has been set.");
Console.ReadKey();
}
private void ViewCurrentText()
{
Console.WriteLine("Current text: " + stringService.CurrentText);
Console.ReadKey();
}
private void ConvertToUpper()
{
Console.WriteLine("Text in upper case: " + stringService.ConvertToUpper());
Console.ReadKey();
}
private void ConvertToLower()
{
Console.WriteLine("Text in lower case: " + stringService.ConvertToLower());
Console.ReadKey();
}
private void CountCharacters()
{
Console.WriteLine("Character Count: " + stringService.CountCharacters());
Console.ReadKey();
}
private void CheckIfContainsWord()
{
Console.WriteLine("Enter word to check: ");
string word = Console.ReadLine();
if(stringService.ContainsWord())
{
Console.WriteLine($"The text contains the word '{word}'.");
}
else
{
Console.WriteLine($"The text does not contain the word '{word}'.");
}
Console.ReadKey();
}
private void ReplaceWord()
{
Console.WriteLine("Enter word to replace: ");
string oldWord = Console.ReadLine();
Console.WriteLine("Enter new word: ");
string newWord = Console.ReadLine();
Console.WriteLine("Updated Text: " + stringService.ReplaceWord(oldWord, newWord));
Console.ReadKey();
}
private void ExtractSubstring()
{
Console.WriteLine("Enter starting index: ");
int startIndex = int.Parse(Console.ReadLine());
Console.WriteLine("Enter length of substring: ");
int length = int.Parse(Console.ReadLine());
Console.WriteLine("Substring: " + stringService.ExtractSubstring(startIndex, length));
Console.ReadKey();
}
private void TrimSpaces()
{
Console.WriteLine("Text afte trim: " + stringService.TrimSpaces());
Console.ReadKey();
}
private void ResetText()
{
stringService.ResetText();
Console.WriteLine("Text has been reset.");
Console.ReadKey();
}
private void Exit()
{
Console.WriteLine("Exiting...... Thank you..");
}
}
}