From cb5cab2221d08fc1df150db52708e27fb22bf75f Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 28 Feb 2026 11:19:57 +0800 Subject: [PATCH 1/3] Implement StringService with various text operations --- SERVICE/StringService.cs | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 SERVICE/StringService.cs diff --git a/SERVICE/StringService.cs b/SERVICE/StringService.cs new file mode 100644 index 0000000..6276794 --- /dev/null +++ b/SERVICE/StringService.cs @@ -0,0 +1,72 @@ +using System; + +namespace StringProcessingApp.Services +{ + public class StringService + { + private string _currentText = ""; + private string _originalText = ""; + + public void SetText(string text) + { + _currentText = text; + _originalText = text; + } + + public string GetText() + { + return _currentText; + } + + public string ConvertToUpper() + { + _currentText = _currentText.ToUpper(); + return _currentText; + } + + public string ConvertToLower() + { + _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 + length <= _currentText.Length) + { + return _currentText.Substring(startIndex, length); + } + else + { + return "Invalid substring range."; + } + } + + public string TrimSpaces() + { + _currentText = _currentText.Trim(); + return _currentText; + } + + public void ResetText() + { + _currentText = _originalText; + } + } +} From 6adb06d94c7444008144b65b8467cb48130cad1a Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 28 Feb 2026 11:21:15 +0800 Subject: [PATCH 2/3] Implement StringView for text processing operations --- VIEWS/StringView.cs | 109 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 VIEWS/StringView.cs diff --git a/VIEWS/StringView.cs b/VIEWS/StringView.cs new file mode 100644 index 0000000..d06a49d --- /dev/null +++ b/VIEWS/StringView.cs @@ -0,0 +1,109 @@ +using System; +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private StringService _service = new StringService(); + + public void Run() + { + bool running = true; + + while (running) + { + DisplayMenu(); + Console.Write("Choose an option: "); + string choice = Console.ReadLine(); + + Console.WriteLine(); + + switch (choice) + { + case "1": + Console.Write("Enter text: "); + string input = Console.ReadLine(); + _service.SetText(input); + break; + + case "2": + Console.WriteLine("Current Text: " + _service.GetText()); + break; + + case "3": + Console.WriteLine("UPPERCASE: " + _service.ConvertToUpper()); + break; + + case "4": + Console.WriteLine("lowercase: " + _service.ConvertToLower()); + break; + + case "5": + Console.WriteLine("Character Count: " + _service.CountCharacters()); + break; + + case "6": + Console.Write("Enter word to check: "); + string word = Console.ReadLine(); + bool contains = _service.ContainsWord(word); + Console.WriteLine(contains ? "Word found." : "Word not found."); + break; + + case "7": + Console.Write("Enter word to replace: "); + string oldWord = Console.ReadLine(); + Console.Write("Enter new word: "); + string newWord = Console.ReadLine(); + Console.WriteLine("Updated Text: " + _service.ReplaceWord(oldWord, newWord)); + break; + + case "8": + Console.Write("Enter start index: "); + int start = int.Parse(Console.ReadLine()); + Console.Write("Enter length: "); + int length = int.Parse(Console.ReadLine()); + Console.WriteLine("Substring: " + _service.ExtractSubstring(start, length)); + break; + + case "9": + Console.WriteLine("Trimmed Text: " + _service.TrimSpaces()); + break; + + case "10": + _service.ResetText(); + Console.WriteLine("Text has been reset."); + break; + + case "11": + running = false; + Console.WriteLine("Exiting program..."); + break; + + default: + Console.WriteLine("Invalid choice. 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("===================================="); + } + } +} From 1aac640ce02c565d3ce58edc191c5af172fe2838 Mon Sep 17 00:00:00 2001 From: hazel Date: Sat, 28 Feb 2026 11:23:31 +0800 Subject: [PATCH 3/3] Add main program entry point with StringView --- 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(); + } + } +}