diff --git a/StringProcessingApp/Program.cs b/StringProcessingApp/Program.cs new file mode 100644 index 0000000..0496be7 --- /dev/null +++ b/StringProcessingApp/Program.cs @@ -0,0 +1,13 @@ +/* +Name: Staley Lane T. Cardeno +Date: 2/28/2026 +Project Description: A console based string-processing system that allows users to input text and perform various string operations using built-in C# String methods. +**/ + +class Program +{ + static void Main(string[] args) + { + StringView view = new StringView(); + view.Run(); + } diff --git a/StringProcessingApp/Services/StringService.cs b/StringProcessingApp/Services/StringService.cs new file mode 100644 index 0000000..c281f9b --- /dev/null +++ b/StringProcessingApp/Services/StringService.cs @@ -0,0 +1,56 @@ +public class StringService +{ + private string originalText = ""; + private string currentText = ""; + + public void SetText(string text) + { + originalText = text; + currentText = text; + } + + public string GetCurrentText() + { + return currentText; + } + + public void ToUpperCase() + { + currentText = currentText.ToUpper(); + } + + public void ToLowerCase() + { + currentText = currentText.ToLower(); + } + + public int CountCharacters() + { + return currentText.Length; + } + + public bool ContainsWord(string word) + { + return currentText.Contains(word); + } + + public void ReplaceWord(string oldWord, string newWord) + { + currentText = currentText.Replace(oldWord, newWord); + } + + public void ExtractSubstring(int start, int length) + { + currentText = currentText.Substring(start, length); + } + + public void TrimSpaces() + { + currentText = currentText.Trim(); + } + + public void ResetText() + { + currentText = originalText; + } +} diff --git a/StringProcessingApp/Views/StringView.cs b/StringProcessingApp/Views/StringView.cs new file mode 100644 index 0000000..d04cfd4 --- /dev/null +++ b/StringProcessingApp/Views/StringView.cs @@ -0,0 +1,91 @@ +public class StringView +{ + private StringService service = new StringService(); + + public void Run() + { + bool running = true; + + while (running) + { + DisplayMenu(); + string choice = Console.ReadLine(); + + switch (choice) + { + case "1": + Console.Write("Enter text: "); + string text = Console.ReadLine(); + service.SetText(text); + break; + + case "2": + Console.WriteLine("Current Text: " + service.GetCurrentText()); + break; + + case "3": + service.ToUpperCase(); + break; + + case "4": + 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(service.ContainsWord(word)); + break; + + case "7": + Console.Write("Word to replace: "); + string oldWord = Console.ReadLine(); + Console.Write("New word: "); + string newWord = Console.ReadLine(); + 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()); + service.ExtractSubstring(start, length); + break; + + case "9": + service.TrimSpaces(); + break; + + case "10": + service.ResetText(); + break; + + case "11": + running = false; + break; + } + } + } + + private void DisplayMenu() + { + Console.WriteLine("\n--- 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.Write("Choose option: "); + } +}