From 3bf1e770081c6e7c172183e23645c8396176d336 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 11:44:10 +0800 Subject: [PATCH 1/9] Create StringService.cs --- StringService.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 StringService.cs diff --git a/StringService.cs b/StringService.cs new file mode 100644 index 0000000..b4c8d8b --- /dev/null +++ b/StringService.cs @@ -0,0 +1,35 @@ +namespace StringProcessingApp.Services +{ + public class StringService + { + private string _originalText = ""; + public string CurrentText { get; private set; } = ""; + + public void SetText(string text) + { + _originalText = text; + CurrentText = text; + } + + public void ToUpper() => CurrentText = CurrentText.ToUpper(); + + public void ToLower() => CurrentText = CurrentText.ToLower(); + + public int GetLength() => CurrentText.Length; + + public bool ContainsWord(string word) => CurrentText.Contains(word); + + public void ReplaceWord(string oldWord, string newWord) + => CurrentText = CurrentText.Replace(oldWord, newWord); + + public void ExtractSubstring(int start, int length) + { + if (start >= 0 && start + length <= CurrentText.Length) + CurrentText = CurrentText.Substring(start, length); + } + + public void TrimSpaces() => CurrentText = CurrentText.Trim(); + + public void Reset() => CurrentText = _originalText; + } +} From 5a39fe92e458be78468be7e2b49391df8565bd75 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 11:44:46 +0800 Subject: [PATCH 2/9] Create StringView.cs --- StringView.cs | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 StringView.cs diff --git a/StringView.cs b/StringView.cs new file mode 100644 index 0000000..1ffd9cc --- /dev/null +++ b/StringView.cs @@ -0,0 +1,78 @@ +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private readonly StringService _service = new StringService(); + + public void Run() + { + bool exit = false; + while (!exit) + { + DisplayMenu(); + string choice = Console.ReadLine() ?? ""; + + switch (choice) + { + case "1": + Console.Write("Enter text: "); + _service.SetText(Console.ReadLine() ?? ""); + break; + case "2": + Console.WriteLine($"Current Text: [{_service.CurrentText}]"); + break; + case "3": _service.ToUpper(); break; + case "4": _service.ToLower(); break; + case "5": + Console.WriteLine($"Character Count: {_service.GetLength()}"); + break; + case "6": + Console.Write("Enter word to find: "); + bool found = _service.ContainsWord(Console.ReadLine() ?? ""); + Console.WriteLine(found ? "Word found!" : "Word not found."); + break; + case "7": + Console.Write("Word to replace: "); + string oldW = Console.ReadLine() ?? ""; + Console.Write("Replace with: "); + string newW = Console.ReadLine() ?? ""; + _service.ReplaceWord(oldW, newW); + break; + case "8": + Console.Write("Start index: "); + int start = int.Parse(Console.ReadLine() ?? "0"); + Console.Write("Length: "); + int len = int.Parse(Console.ReadLine() ?? "0"); + _service.ExtractSubstring(start, len); + break; + case "9": _service.TrimSpaces(); break; + case "10": _service.Reset(); break; + case "11": exit = true; break; + default: Console.WriteLine("Invalid option."); break; + } + Console.WriteLine("\nPress any key to continue..."); + Console.ReadKey(); + } + } + + private void DisplayMenu() + { + Console.Clear(); + Console.WriteLine("--- String Processing System ---"); + Console.WriteLine("1. Enter Text"); + Console.WriteLine("2. View Current Text"); + Console.WriteLine("3. Convert to UPPERCASE"); + Console.WriteLine("4. Convert to lowercase"); + Console.WriteLine("5. Count Characters"); + Console.WriteLine("6. Check if Contains Word"); + 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.Write("\nSelect an option: "); + } + } +} From dee456b02a360f80bff7f559beb88fe2f212d527 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 11:45:18 +0800 Subject: [PATCH 3/9] Create Program.cs --- Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program.cs diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..bcbb9dc --- /dev/null +++ b/Program.cs @@ -0,0 +1,10 @@ +using StringProcessingApp.Views; + +class Program +{ + static void Main(string[] args) + { + StringView view = new StringView(); + view.Run(); + } +} From 94e7b2e3e4dfd565b2dfeac9363f755bc98cce45 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 11:48:17 +0800 Subject: [PATCH 4/9] Update StringView.cs --- StringView.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/StringView.cs b/StringView.cs index 1ffd9cc..f4614f3 100644 --- a/StringView.cs +++ b/StringView.cs @@ -1,3 +1,4 @@ +using System; using StringProcessingApp.Services; namespace StringProcessingApp.Views From a91421f5d8c412643bbd531c418fcaab615640a3 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 12:07:44 +0800 Subject: [PATCH 5/9] Update Program.cs --- Program.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index bcbb9dc..f1a0983 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,13 @@ -using StringProcessingApp.Views; +using System; -class Program +namespace StringProcessingApp { - static void Main(string[] args) + class Program { - StringView view = new StringView(); - view.Run(); + static void Main(string[] args) + { + StringView myView = new StringView(); + myView.Run(); + } } } From 3372a4ed6e115349110deb2f37ce465386e07553 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 12:10:03 +0800 Subject: [PATCH 6/9] Update StringService.cs --- StringService.cs | 55 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/StringService.cs b/StringService.cs index b4c8d8b..acd2f37 100644 --- a/StringService.cs +++ b/StringService.cs @@ -1,35 +1,60 @@ -namespace StringProcessingApp.Services +using System; + +namespace StringProcessingApp { public class StringService { - private string _originalText = ""; - public string CurrentText { get; private set; } = ""; + private string originalText = ""; + public string CurrentText = ""; public void SetText(string text) { - _originalText = text; + originalText = text; CurrentText = text; } - public void ToUpper() => CurrentText = CurrentText.ToUpper(); + public void ToUpper() + { + CurrentText = CurrentText.ToUpper(); + } - public void ToLower() => CurrentText = CurrentText.ToLower(); + public void ToLower() + { + CurrentText = CurrentText.ToLower(); + } - public int GetLength() => CurrentText.Length; + public int GetLength() + { + return CurrentText.Length; + } - public bool ContainsWord(string word) => CurrentText.Contains(word); + public bool ContainsWord(string word) + { + return CurrentText.Contains(word); + } - public void ReplaceWord(string oldWord, string newWord) - => CurrentText = CurrentText.Replace(oldWord, newWord); + public void ReplaceWord(string oldWord, string newWord) + { + CurrentText = CurrentText.Replace(oldWord, newWord); + } - public void ExtractSubstring(int start, int length) + public void ExtractSubstring(int start, int len) { - if (start >= 0 && start + length <= CurrentText.Length) - CurrentText = CurrentText.Substring(start, length); + + if (start >= 0 && (start + len) <= CurrentText.Length) + { + CurrentText = CurrentText.Substring(start, len); + } } - public void TrimSpaces() => CurrentText = CurrentText.Trim(); + public void TrimSpaces() + { + CurrentText = currentText.Trim(); + } - public void Reset() => CurrentText = _originalText; + public void Reset() + { + CurrentText = originalText; + } } } From 1bc2e2b56f28edfa06ab24f7d1e42c300257df5f Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 12:14:14 +0800 Subject: [PATCH 7/9] Update StringView.cs --- StringView.cs | 142 +++++++++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 55 deletions(-) diff --git a/StringView.cs b/StringView.cs index f4614f3..cb2215a 100644 --- a/StringView.cs +++ b/StringView.cs @@ -1,79 +1,111 @@ using System; -using StringProcessingApp.Services; -namespace StringProcessingApp.Views +namespace StringProcessingApp { public class StringView { - private readonly StringService _service = new StringService(); + private StringService service = new StringService(); public void Run() { - bool exit = false; - while (!exit) + bool running = true; + + while (running) { DisplayMenu(); - string choice = Console.ReadLine() ?? ""; + string choice = Console.ReadLine(); - switch (choice) + if (choice == "1") + { + Console.Write("Enter your text: "); + string input = Console.ReadLine(); + service.SetText(input); + } + else if (choice == "2") + { + Console.WriteLine("Current Text: " + service.CurrentText); + } + else if (choice == "3") + { + service.ToUpper(); + Console.WriteLine("Changed to UPPERCASE."); + } + else if (choice == "4") + { + service.ToLower(); + Console.WriteLine("Changed to lowercase."); + } + else if (choice == "5") + { + int len = service.GetLength(); + Console.WriteLine("Total characters: " + len); + } + else if (choice == "6") + { + Console.Write("Enter word to search: "); + string find = Console.ReadLine(); + if (service.ContainsWord(find)) { + Console.WriteLine("Found it!"); + } else { + Console.WriteLine("Not found."); + } + } + else if (choice == "7") + { + Console.Write("Old word: "); + string oldW = Console.ReadLine(); + Console.Write("New word: "); + string newW = Console.ReadLine(); + service.ReplaceWord(oldW, newW); + } + else if (choice == "8") + { + Console.Write("Start index: "); + int start = int.Parse(Console.ReadLine()); + Console.Write("Length: "); + int len = int.Parse(Console.ReadLine()); + service.ExtractSubstring(start, len); + } + else if (choice == "9") + { + service.TrimSpaces(); + Console.WriteLine("Spaces removed."); + } + else if (choice == "10") + { + service.Reset(); + Console.WriteLine("Text reset to original."); + } + else if (choice == "11") { - case "1": - Console.Write("Enter text: "); - _service.SetText(Console.ReadLine() ?? ""); - break; - case "2": - Console.WriteLine($"Current Text: [{_service.CurrentText}]"); - break; - case "3": _service.ToUpper(); break; - case "4": _service.ToLower(); break; - case "5": - Console.WriteLine($"Character Count: {_service.GetLength()}"); - break; - case "6": - Console.Write("Enter word to find: "); - bool found = _service.ContainsWord(Console.ReadLine() ?? ""); - Console.WriteLine(found ? "Word found!" : "Word not found."); - break; - case "7": - Console.Write("Word to replace: "); - string oldW = Console.ReadLine() ?? ""; - Console.Write("Replace with: "); - string newW = Console.ReadLine() ?? ""; - _service.ReplaceWord(oldW, newW); - break; - case "8": - Console.Write("Start index: "); - int start = int.Parse(Console.ReadLine() ?? "0"); - Console.Write("Length: "); - int len = int.Parse(Console.ReadLine() ?? "0"); - _service.ExtractSubstring(start, len); - break; - case "9": _service.TrimSpaces(); break; - case "10": _service.Reset(); break; - case "11": exit = true; break; - default: Console.WriteLine("Invalid option."); break; + running = false; } - Console.WriteLine("\nPress any key to continue..."); - Console.ReadKey(); + else + { + Console.WriteLine("Invalid choice, try again."); + } + + Console.WriteLine("\nPress enter to continue..."); + Console.ReadLine(); } } private void DisplayMenu() { Console.Clear(); - Console.WriteLine("--- String Processing System ---"); - Console.WriteLine("1. Enter Text"); - Console.WriteLine("2. View Current Text"); - Console.WriteLine("3. Convert to UPPERCASE"); - Console.WriteLine("4. Convert to lowercase"); - Console.WriteLine("5. Count Characters"); - Console.WriteLine("6. Check if Contains Word"); + Console.WriteLine("--- STRING PROCESSOR ---"); + Console.WriteLine("1. Set Text"); + Console.WriteLine("2. Show Text"); + Console.WriteLine("3. To Uppercase"); + Console.WriteLine("4. To Lowercase"); + Console.WriteLine("5. Character Count"); + Console.WriteLine("6. Find Word"); Console.WriteLine("7. Replace Word"); - Console.WriteLine("8. Extract Substring"); - Console.WriteLine("9. Trim Spaces"); - Console.WriteLine("10. Reset Text"); + Console.WriteLine("8. Substring"); + Console.WriteLine("9. Trim"); + Console.WriteLine("10. Reset"); Console.WriteLine("11. Exit"); - Console.Write("\nSelect an option: "); + Console.Write("Selection: "); } } } From ebfa0974d3506f244e5110760346b2cba9cc69b8 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 12:15:06 +0800 Subject: [PATCH 8/9] Update StringService.cs --- StringService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/StringService.cs b/StringService.cs index acd2f37..5f3d991 100644 --- a/StringService.cs +++ b/StringService.cs @@ -40,7 +40,6 @@ public void ReplaceWord(string oldWord, string newWord) public void ExtractSubstring(int start, int len) { - if (start >= 0 && (start + len) <= CurrentText.Length) { CurrentText = CurrentText.Substring(start, len); From d8e77c07dc421f64920e5f4f869a29f83a4dce53 Mon Sep 17 00:00:00 2001 From: JessieDomenicActub-UCM Date: Sat, 28 Feb 2026 12:28:45 +0800 Subject: [PATCH 9/9] Update StringView.cs --- StringView.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/StringView.cs b/StringView.cs index cb2215a..b0c62bc 100644 --- a/StringView.cs +++ b/StringView.cs @@ -94,16 +94,16 @@ private void DisplayMenu() { Console.Clear(); Console.WriteLine("--- STRING PROCESSOR ---"); - Console.WriteLine("1. Set Text"); - Console.WriteLine("2. Show Text"); - Console.WriteLine("3. To Uppercase"); - Console.WriteLine("4. To Lowercase"); - Console.WriteLine("5. Character Count"); - Console.WriteLine("6. Find Word"); + Console.WriteLine("1.Enter Text"); + Console.WriteLine("2. View Current text"); + Console.WriteLine("3. Convert to UPPERCASE"); + Console.WriteLine("4. Convert to lowercase"); + Console.WriteLine("5. Count Character"); + Console.WriteLine("6. Check if it Contain Word"); Console.WriteLine("7. Replace Word"); - Console.WriteLine("8. Substring"); - Console.WriteLine("9. Trim"); - Console.WriteLine("10. Reset"); + Console.WriteLine("8. Extract Substring"); + Console.WriteLine("9. Trim Spaces"); + Console.WriteLine("10. Reset Text"); Console.WriteLine("11. Exit"); Console.Write("Selection: "); }