From 8635208ab1600926f252f592e88498ffd5490786 Mon Sep 17 00:00:00 2001 From: Kenjay Lungayan Date: Sun, 1 Mar 2026 00:09:26 +0800 Subject: [PATCH] Add files via upload --- Program.cs | 13 ++++++ StringService.cs | 65 +++++++++++++++++++++++++++++ StringView.cs | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 Program.cs create mode 100644 StringService.cs create mode 100644 StringView.cs diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..6594209 --- /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(); + } + } +} \ No newline at end of file diff --git a/StringService.cs b/StringService.cs new file mode 100644 index 0000000..482e265 --- /dev/null +++ b/StringService.cs @@ -0,0 +1,65 @@ +using System; + +namespace StringProcessingApp.Services +{ + public class StringService + { + private string originalText = ""; + private string 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) + { + return currentText.Substring(startIndex, length); + } + + public string TrimSpaces() + { + currentText = currentText.Trim(); + return currentText; + } + + public void ResetText() + { + currentText = originalText; + } + } +} \ No newline at end of file diff --git a/StringView.cs b/StringView.cs new file mode 100644 index 0000000..7d5926d --- /dev/null +++ b/StringView.cs @@ -0,0 +1,104 @@ +using System; +using StringProcessingApp.Services; + +namespace StringProcessingApp.Views +{ + public class StringView + { + private StringService service = new StringService(); + private bool isRunning = true; + + public void Run() + { + while (isRunning) + { + DisplayMenu(); + Console.Write("Choose an option: "); + string choice = Console.ReadLine(); + Console.WriteLine(); + + switch (choice) + { + case "1": + Console.Write("Enter text: "); + service.SetText(Console.ReadLine()); + break; + + case "2": + Console.WriteLine("Current Text: " + service.GetText()); + 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": + Console.Write("Enter word to check: "); + string word = Console.ReadLine(); + Console.WriteLine("Contains? " + service.ContainsWord(word)); + break; + + case "7": + Console.Write("Word to replace: "); + string oldWord = Console.ReadLine(); + Console.Write("New word: "); + string newWord = Console.ReadLine(); + Console.WriteLine("Updated Text: " + service.ReplaceWord(oldWord, newWord)); + break; + + case "8": + Console.Write("Start Index: "); + int start = int.Parse(Console.ReadLine()); + Console.Write("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 reset to original."); + break; + + case "11": + isRunning = false; + break; + + default: + Console.WriteLine("Invalid option."); + 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("======================================"); + } + } +} \ No newline at end of file