From c56a0c647aa59c396191aff53c16e0e69c2bc9ec Mon Sep 17 00:00:00 2001 From: Kurt Suba-an <112990419+Kurtdio@users.noreply.github.com> Date: Sat, 7 Mar 2026 08:28:04 +0800 Subject: [PATCH 1/3] Program.cs --- Program.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Program.cs diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..33de641 --- /dev/null +++ b/Program.cs @@ -0,0 +1,13 @@ +using StringProcessingApp.Views; + +namespace StringProcessingApp +{ + class Program + { + static void Main(string[] args) + { + StringView view = new StringView(); + view.Run(); + } + } +} From ec0f4bb6980ca4756baa8f26de26e43afe03687c Mon Sep 17 00:00:00 2001 From: Kurt Suba-an <112990419+Kurtdio@users.noreply.github.com> Date: Sat, 7 Mar 2026 08:29:47 +0800 Subject: [PATCH 2/3] StringService.cs --- StringService.cs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 StringService.cs diff --git a/StringService.cs b/StringService.cs new file mode 100644 index 0000000..0c43905 --- /dev/null +++ b/StringService.cs @@ -0,0 +1,85 @@ +using System; + +namespace StringProcessingApp.Services +{ + public class StringService + { + private string _originalText; + private string _currentText; + + public StringService() + { + _originalText = ""; + _currentText = ""; + } + + + public void SetText(string text) + { + _originalText = text; + _currentText = text; + } + + + public string GetText() + { + return _currentText; + } + + + public string ToUpperCase() + { + _currentText = _currentText.ToUpper(); + return _currentText; + } + + + public string ToLowerCase() + { + _currentText = _currentText.ToLower(); + return _currentText; + } + + + public int CountCharacters() + { + return _currentText.Length; + } + + + public bool ContainsWord(string word) + { + return _currentText.Contains(word); + } + + + public string ReplaceWord(string oldWord, string newWord) + { + _currentText = _currentText.Replace(oldWord, newWord); + return _currentText; + } + + + public string ExtractSubstring(int startIndex, int length) + { + if (startIndex < 0 || startIndex >= _currentText.Length || length < 0) + return "Invalid indices"; + if (startIndex + length > _currentText.Length) + length = _currentText.Length - startIndex; + return _currentText.Substring(startIndex, length); + } + + + public string TrimSpaces() + { + _currentText = _currentText.Trim(); + return _currentText; + } + + + public void ResetText() + { + _currentText = _originalText; + } + } +} From 669e7e3e71cad7251866fce678c5ca78427752e6 Mon Sep 17 00:00:00 2001 From: Kurt Suba-an <112990419+Kurtdio@users.noreply.github.com> Date: Sat, 7 Mar 2026 08:30:47 +0800 Subject: [PATCH 3/3] StringView.cs --- StringView.cs | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 StringView.cs diff --git a/StringView.cs b/StringView.cs new file mode 100644 index 0000000..e5a4054 --- /dev/null +++ b/StringView.cs @@ -0,0 +1,140 @@ +using System; +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private StringService _service; + + public StringView() + { + _service = new StringService(); + } + + public void Run() + { + bool exit = false; + while (!exit) + { + DisplayMenu(); + Console.Write("Choose an option: "); + string input = Console.ReadLine(); + Console.WriteLine(); + + switch (input) + { + case "1": + EnterText(); + break; + case "2": + ViewCurrentText(); + break; + case "3": + Console.WriteLine("Uppercase: " + _service.ToUpperCase()); + break; + case "4": + Console.WriteLine("Lowercase: " + _service.ToLowerCase()); + break; + case "5": + Console.WriteLine("Character count: " + _service.CountCharacters()); + break; + case "6": + CheckContainsWord(); + break; + case "7": + ReplaceWord(); + break; + case "8": + ExtractSubstring(); + break; + case "9": + Console.WriteLine("Trimmed text: " + _service.TrimSpaces()); + break; + case "10": + _service.ResetText(); + Console.WriteLine("Text reset to original."); + break; + case "11": + exit = true; + Console.WriteLine("Exiting..."); + break; + default: + Console.WriteLine("Invalid option. Try again."); + break; + } + + Console.WriteLine(); + } + } + + private void DisplayMenu() + { + 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.WriteLine("================================"); + } + + private void EnterText() + { + Console.Write("Enter your text: "); + string text = Console.ReadLine(); + _service.SetText(text); + Console.WriteLine("Text saved successfully."); + } + + private void ViewCurrentText() + { + string text = _service.GetText(); + Console.WriteLine("Current Text: " + (string.IsNullOrEmpty(text) ? "[Empty]" : text)); + } + + private void CheckContainsWord() + { + Console.Write("Enter word to check: "); + string word = Console.ReadLine(); + bool exists = _service.ContainsWord(word); + Console.WriteLine(exists ? $"Text contains '{word}'." : $"Text does not contain '{word}'."); + } + + private void ReplaceWord() + { + Console.Write("Enter word to replace: "); + string oldWord = Console.ReadLine(); + Console.Write("Enter new word: "); + string newWord = Console.ReadLine(); + string result = _service.ReplaceWord(oldWord, newWord); + Console.WriteLine("Updated Text: " + result); + } + + private void ExtractSubstring() + { + Console.Write("Enter start index: "); + if (!int.TryParse(Console.ReadLine(), out int start)) + { + Console.WriteLine("Invalid input."); + return; + } + + Console.Write("Enter length: "); + if (!int.TryParse(Console.ReadLine(), out int length)) + { + Console.WriteLine("Invalid input."); + return; + } + + string substring = _service.ExtractSubstring(start, length); + Console.WriteLine("Substring: " + substring); + } + } +}