I have an application
namespace Aplikacija1
{
public class excercise5
{
static void Main(string[] args)
{
Console.WriteLine("Enter word :");
string word = Console.ReadLine();
Console.WriteLine("Enter the letter :");
string letter = Console.ReadLine();
int charPos = word.IndexOf($"{letter}");
Console.WriteLine(word.Remove(charPos, 1));
}
}
}
so it should remove a letter from the string which is entered.
If I enter word Nikola and letter a the result is Nikol which is correct
But if I enter word Nikala and the letter a the result is Nikla, with no option to remove second a, or choose which a I want to remove
Is there a way to add something to my code to make it work?
>Solution :
You could use the Replace() method and replace it with an empty string:
string wordWithoutLetter = word.Replace(letter, "");
Console.WriteLine(wordWithoutLetter);