From e7408d10eea1c39e41e3fdf446a99385f3e6a8eb Mon Sep 17 00:00:00 2001 From: crossfireaccs19-cloud Date: Sat, 28 Feb 2026 11:36:08 +0800 Subject: [PATCH 1/3] Create StringService.cs --- StringService.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 StringService.cs diff --git a/StringService.cs b/StringService.cs new file mode 100644 index 0000000..82509bd --- /dev/null +++ b/StringService.cs @@ -0,0 +1,41 @@ +using System; + +namespace StringProcessingApp.Services +{ + public class StringService + { + private string _originalText = string.Empty; + private string _currentText = string.Empty; + + public void SetText(string text) + { + _originalText = text; + _currentText = text; + } + + public string GetCurrentText() => _currentText; + + 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, StringComparison.OrdinalIgnoreCase); + + public void ReplaceWord(string oldWord, string newWord) => + _currentText = _currentText.Replace(oldWord, newWord); + + public string ExtractSubstring(int startIndex, int length) + { + if (startIndex < 0 || startIndex + length > _currentText.Length) + return "Error: Out of range."; + + return _currentText.Substring(startIndex, length); + } + + public void TrimSpaces() => _currentText = _currentText.Trim(); + + public void Reset() => _currentText = _originalText; + } +} From f136dea4b2d776cb03327b5fb431413686c513f1 Mon Sep 17 00:00:00 2001 From: crossfireaccs19-cloud Date: Sat, 28 Feb 2026 11:37:26 +0800 Subject: [PATCH 2/3] Create StringView.cs --- StringView.cs | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 StringView.cs diff --git a/StringView.cs b/StringView.cs new file mode 100644 index 0000000..5412719 --- /dev/null +++ b/StringView.cs @@ -0,0 +1,99 @@ +using System; +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private readonly StringService _service = new StringService(); + + public void Run() + { + string choice = ""; + while (choice != "11") + { + DisplayMenu(); + choice = Console.ReadLine(); + ProcessChoice(choice); + if (choice != "11") + { + Console.WriteLine("\nPress any key to continue..."); + Console.ReadKey(); + } + } + } + + private void DisplayMenu() + { + Console.Clear(); + Console.WriteLine("=== String Processing System ==="); + Console.WriteLine($"Current Text: \"{_service.GetCurrentText()}\""); + Console.WriteLine("--------------------------------"); + 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: "); + } + + private void ProcessChoice(string choice) + { + switch (choice) + { + case "1": + Console.Write("Enter new text: "); + _service.SetText(Console.ReadLine()); + break; + case "2": + Console.WriteLine($"Current Text: {_service.GetCurrentText()}"); + break; + case "3": + _service.ToUpper(); + Console.WriteLine("Converted to UPPERCASE."); + break; + case "4": + _service.ToLower(); + Console.WriteLine("Converted to lowercase."); + break; + case "5": + Console.WriteLine($"Length: {_service.GetLength()} characters."); + break; + case "6": + Console.Write("Enter word to find: "); + string word = Console.ReadLine(); + bool found = _service.ContainsWord(word); + Console.WriteLine(found ? "Word found!" : "Word not found."); + break; + case "7": + Console.Write("Word to replace: "); + string oldW = Console.ReadLine(); + Console.Write("Replacement word: "); + string newW = Console.ReadLine(); + _service.ReplaceWord(oldW, newW); + break; + case "8": + Console.Write("Start Index: "); + int start = int.Parse(Console.ReadLine()); + Console.Write("Length: "); + int len = int.Parse(Console.ReadLine()); + Console.WriteLine($"Result: {_service.ExtractSubstring(start, len)}"); + break; + case "9": + _service.TrimSpaces(); + Console.WriteLine("Spaces trimmed."); + break; + case "10": + _service.Reset(); + Console.WriteLine("Text reset to original."); + break; + } + } + } +} From 75bb89074cd05ab3ab327372ea61d2ffdd858981 Mon Sep 17 00:00:00 2001 From: crossfireaccs19-cloud Date: Sat, 28 Feb 2026 11:38:10 +0800 Subject: [PATCH 3/3] Create 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(); + } + } +}