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
11 changes: 11 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

public class Program
{
public static void Main(String[] args)
{
StringView view = new StringView();

view.Menu();
}
}
81 changes: 81 additions & 0 deletions Service/StringService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;

public class StringService
{
public void CheckNullOrEmpty(String text)
{
if (string.IsNullOrEmpty(text))
{
Console.WriteLine("Enter a text first");
Console.WriteLine();
Console.WriteLine();
}
}

public void ConvertUppercase(String text)
{
if (string.IsNullOrEmpty(text))
{
CheckNullOrEmpty(text);
}
else
{
Console.WriteLine(text.ToUpper());
Console.WriteLine();
Console.WriteLine();
}

}
public void ConvertLowercase(String text)
{
if (string.IsNullOrEmpty(text))
{
CheckNullOrEmpty(text);
}
else
{
Console.WriteLine(text.ToLower());
Console.WriteLine();
Console.WriteLine();
}
}
public int CountCharacters(String text)
{
return text.Length;
}
public bool Contains(String text, String searchWord)
{
if(string.IsNullOrEmpty(text) || string.IsNullOrEmpty(searchWord))
{
return false;
}
return text.Contains(searchWord);
}
public string ReplaceWord(string currentText, string oldWord, string newWord)
{
if (string.IsNullOrEmpty(currentText))
{
return "";
}
return currentText.Replace(oldWord, newWord);
}

public string Substring(string input, int startIndex, int length)
{
if (string.IsNullOrEmpty(input)) return "";

return input.Substring(startIndex, length);
}

public string Trim(string input)
{
if (string.IsNullOrEmpty(input)) return "";

return input.Trim();
}

public String Reset(string originalText)
{
return originalText;
}
}
138 changes: 138 additions & 0 deletions View/StringView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;

public class StringView
{
public void Menu()
{
StringService service = new StringService();
String text = "";
String originalText = "";

bool running = true;
while (running)
{

Console.WriteLine("---- Display Menu ----");
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");

String displayOptions = Console.ReadLine();

switch (displayOptions)
{
case "1":
Console.WriteLine("Enter a text: ");
text = Console.ReadLine();
Console.WriteLine();
Console.WriteLine();
break;

case "2":
if (string.IsNullOrEmpty(text))
{
service.CheckNullOrEmpty(text);
}
else
{
Console.WriteLine(text);
Console.WriteLine();
Console.WriteLine();
}
break;

case "3":
service.ConvertUppercase(text);
break;

case "4":
service.ConvertLowercase(text);
break;

case "5":
if(string.IsNullOrEmpty(text))
{
service.CheckNullOrEmpty(text);
}
else
{
int count = service.CountCharacters(text);

Console.WriteLine($"Characters Count: {count}");
}
break;
case "6":
Console.Write("Enter the word to search for: ");
string word = Console.ReadLine();

bool found = service.Contains(text, word);

if (found)
{
Console.WriteLine($"Result: Yes, the word '{word}' was found!");
}
else
{
Console.WriteLine($"Result: No, the word '{word}' is not in the text.");
}
Console.WriteLine();
break;

case "7":
if (string.IsNullOrEmpty(text))
{
Console.WriteLine("Error: Please enter text first (Option 1).");
}
else
{
Console.Write("Enter the word you want to change: ");
string target = Console.ReadLine();

Console.Write("Enter the new word: ");
string replacement = Console.ReadLine();

text = service.ReplaceWord(text, target, replacement);

Console.WriteLine($"Updated Text: {text}");
}
Console.WriteLine();
break;

case "8":
Console.Write("Enter starting index (0 is the first letter): ");
int.TryParse(Console.ReadLine(), out int start);

Console.Write("Enter how many characters to extract: ");
int.TryParse(Console.ReadLine(), out int len);

string result = service.Substring(text, start, len);
Console.WriteLine($"Extracted part: {result}");
break;

case "9":
text = service.Trim(text); // Update the text variable
Console.WriteLine("Spaces trimmed from the ends!");
break;

case "10":
text = service.Reset(originalText);
Console.WriteLine("Text reset to original!");
break;

case "11":
Console.Write("Exiting...");
running = false;
break;
}
}
}
}