Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using StringProcessingApp.Views;

namespace StringProcessingApp
{
class Program
{
static void Main(string[] args)
{
StringView view = new StringView();
view.Run();
}
}
}
72 changes: 72 additions & 0 deletions SERVICE/StringService.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
109 changes: 109 additions & 0 deletions VIEWS/StringView.cs
Original file line number Diff line number Diff line change
@@ -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("====================================");
}
}
}