From f2ff643f317703347e6183f11b8f3d06058210e7 Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 10:58:40 +0800 Subject: [PATCH 1/7] Create StringService.cs --- Services/StringService.cs | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Services/StringService.cs diff --git a/Services/StringService.cs b/Services/StringService.cs new file mode 100644 index 0000000..bd67863 --- /dev/null +++ b/Services/StringService.cs @@ -0,0 +1,40 @@ +namespace StringProcessingApp.Services +{ + public class StringService + { + private string originalText = ""; + private string currentText = ""; + + public void SetText(string text) + { + originalText = text; + currentText = text; + } + + public string GetCurrentText() => currentText; + + public string ToUpperCase() => currentText = currentText.ToUpper(); + + public string ToLowerCase() => currentText = currentText.ToLower(); + + public int CountCharacters() => currentText.Length; + + public bool ContainsWord(string word) => currentText.Contains(word); + + public string ReplaceWord(string oldWord, string newWord) + => currentText = currentText.Replace(oldWord, newWord); + + public string ExtractSubstring(int startIndex, int length) + => currentText.Substring(startIndex, length); + + public string TrimSpaces() => currentText = currentText.Trim(); + + public string ResetText() + { + currentText = originalText; + return currentText; + } + + public bool HasText() => !string.IsNullOrEmpty(currentText); + } +} From acb9ac43bd7affbb46bf373848c658c77d355005 Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 10:59:54 +0800 Subject: [PATCH 2/7] Create StringProcessingApp --- StringProcessingApp | 1 + 1 file changed, 1 insertion(+) create mode 100644 StringProcessingApp diff --git a/StringProcessingApp b/StringProcessingApp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/StringProcessingApp @@ -0,0 +1 @@ + From 5044152ed576f6b32f149331c4567ee1697c3db2 Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 11:01:14 +0800 Subject: [PATCH 3/7] Delete Services directory --- Services/StringService.cs | 40 --------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 Services/StringService.cs diff --git a/Services/StringService.cs b/Services/StringService.cs deleted file mode 100644 index bd67863..0000000 --- a/Services/StringService.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace StringProcessingApp.Services -{ - public class StringService - { - private string originalText = ""; - private string currentText = ""; - - public void SetText(string text) - { - originalText = text; - currentText = text; - } - - public string GetCurrentText() => currentText; - - public string ToUpperCase() => currentText = currentText.ToUpper(); - - public string ToLowerCase() => currentText = currentText.ToLower(); - - public int CountCharacters() => currentText.Length; - - public bool ContainsWord(string word) => currentText.Contains(word); - - public string ReplaceWord(string oldWord, string newWord) - => currentText = currentText.Replace(oldWord, newWord); - - public string ExtractSubstring(int startIndex, int length) - => currentText.Substring(startIndex, length); - - public string TrimSpaces() => currentText = currentText.Trim(); - - public string ResetText() - { - currentText = originalText; - return currentText; - } - - public bool HasText() => !string.IsNullOrEmpty(currentText); - } -} From 516edb5eea2254b5fadeaa6280cafc2c0b6305be Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 11:03:43 +0800 Subject: [PATCH 4/7] Delete StringProcessingApp --- StringProcessingApp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 StringProcessingApp diff --git a/StringProcessingApp b/StringProcessingApp deleted file mode 100644 index 8b13789..0000000 --- a/StringProcessingApp +++ /dev/null @@ -1 +0,0 @@ - From c5ae9648b0d2e57a8c1f01c8690c4a4fb1cb9701 Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 11:05:04 +0800 Subject: [PATCH 5/7] Create StringService.cs --- StringProcessingApp/Services/StringService.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 StringProcessingApp/Services/StringService.cs diff --git a/StringProcessingApp/Services/StringService.cs b/StringProcessingApp/Services/StringService.cs new file mode 100644 index 0000000..bd67863 --- /dev/null +++ b/StringProcessingApp/Services/StringService.cs @@ -0,0 +1,40 @@ +namespace StringProcessingApp.Services +{ + public class StringService + { + private string originalText = ""; + private string currentText = ""; + + public void SetText(string text) + { + originalText = text; + currentText = text; + } + + public string GetCurrentText() => currentText; + + public string ToUpperCase() => currentText = currentText.ToUpper(); + + public string ToLowerCase() => currentText = currentText.ToLower(); + + public int CountCharacters() => currentText.Length; + + public bool ContainsWord(string word) => currentText.Contains(word); + + public string ReplaceWord(string oldWord, string newWord) + => currentText = currentText.Replace(oldWord, newWord); + + public string ExtractSubstring(int startIndex, int length) + => currentText.Substring(startIndex, length); + + public string TrimSpaces() => currentText = currentText.Trim(); + + public string ResetText() + { + currentText = originalText; + return currentText; + } + + public bool HasText() => !string.IsNullOrEmpty(currentText); + } +} From 9a040156b7bee7ecddf84d16b89accfaa95d244a Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 11:06:42 +0800 Subject: [PATCH 6/7] Create StringView.cs --- StringProcessingApp/Views/StringView.cs | 180 ++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 StringProcessingApp/Views/StringView.cs diff --git a/StringProcessingApp/Views/StringView.cs b/StringProcessingApp/Views/StringView.cs new file mode 100644 index 0000000..8472a96 --- /dev/null +++ b/StringProcessingApp/Views/StringView.cs @@ -0,0 +1,180 @@ +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private readonly 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": + EnterText(); + break; + case "2": + ViewCurrentText(); + break; + case "3": + ConvertToUpper(); + break; + case "4": + ConvertToLower(); + break; + case "5": + CountCharacters(); + break; + case "6": + CheckContains(); + break; + case "7": + ReplaceWord(); + break; + case "8": + ExtractSubstring(); + break; + case "9": + TrimSpaces(); + break; + case "10": + ResetText(); + break; + case "11": + running = false; + Console.WriteLine("Goodbye!"); + break; + default: + Console.WriteLine("Invalid option. Please try again."); + break; + } + + Console.WriteLine(); + } + } + + private void DisplayMenu() + { + Console.WriteLine("============================="); + Console.WriteLine(" STRING PROCESSING SYSTEM "); + 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.WriteLine("============================="); + } + + private void EnterText() + { + Console.Write("Enter your text: "); + string? input = Console.ReadLine(); + if (!string.IsNullOrEmpty(input)) + { + _service.SetText(input); + Console.WriteLine("Text saved successfully!"); + } + else + { + Console.WriteLine("No text entered."); + } + } + + private void ViewCurrentText() + { + if (!_service.HasText()) + Console.WriteLine("No text entered yet."); + else + Console.WriteLine($"Current Text: \"{_service.GetCurrentText()}\""); + } + + private void ConvertToUpper() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"UPPERCASE: \"{_service.ToUpperCase()}\""); + } + + private void ConvertToLower() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"lowercase: \"{_service.ToLowerCase()}\""); + } + + private void CountCharacters() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"Character Count: {_service.CountCharacters()}"); + } + + private void CheckContains() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.Write("Enter word to search: "); + string? word = Console.ReadLine(); + if (string.IsNullOrEmpty(word)) { Console.WriteLine("No word entered."); return; } + bool found = _service.ContainsWord(word); + Console.WriteLine(found + ? $"✓ The text contains \"{word}\"." + : $"✗ The text does NOT contain \"{word}\"."); + } + + private void ReplaceWord() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.Write("Enter word to replace: "); + string? oldWord = Console.ReadLine(); + Console.Write("Enter new word: "); + string? newWord = Console.ReadLine(); + if (string.IsNullOrEmpty(oldWord) || newWord == null) { Console.WriteLine("Invalid input."); return; } + Console.WriteLine($"Result: \"{_service.ReplaceWord(oldWord, newWord)}\""); + } + + private void ExtractSubstring() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"Current Text: \"{_service.GetCurrentText()}\" (Length: {_service.CountCharacters()})"); + Console.Write("Enter start index: "); + if (!int.TryParse(Console.ReadLine(), out int start)) { Console.WriteLine("Invalid index."); return; } + Console.Write("Enter length: "); + if (!int.TryParse(Console.ReadLine(), out int length)) { Console.WriteLine("Invalid length."); return; } + + try + { + Console.WriteLine($"Substring: \"{_service.ExtractSubstring(start, length)}\""); + } + catch (ArgumentOutOfRangeException) + { + Console.WriteLine("Error: Index or length is out of range."); + } + } + + private void TrimSpaces() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"Trimmed: \"{_service.TrimSpaces()}\""); + } + + private void ResetText() + { + if (!_service.HasText()) { Console.WriteLine("Please enter text first."); return; } + Console.WriteLine($"Text reset to: \"{_service.ResetText()}\""); + } + } +} From ee323102baf5cc10378c7f7676b34714aee543dc Mon Sep 17 00:00:00 2001 From: Lynsy Date: Sat, 28 Feb 2026 11:07:51 +0800 Subject: [PATCH 7/7] Create Program.cs --- StringProcessingApp/Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 StringProcessingApp/Program.cs diff --git a/StringProcessingApp/Program.cs b/StringProcessingApp/Program.cs new file mode 100644 index 0000000..bcbb9dc --- /dev/null +++ b/StringProcessingApp/Program.cs @@ -0,0 +1,10 @@ +using StringProcessingApp.Views; + +class Program +{ + static void Main(string[] args) + { + StringView view = new StringView(); + view.Run(); + } +}