Console.WriteLine(wordsText[2] + wordsText[3] + wordsText[4] + wordsText[5] + "___");
If you would like to replace '
dog
' with '
___
', you need to use
string.Replace[
^] method. See:
string[] sentences = {
"dog - I took my dog for a walk",
"door - I opened the front door of my house",
"choose - you need to choose an item"
};
for(int i=0; i<sentences.Length; i++)
{
string sentence = sentences[i];
string word = sentence.Split(new string[]{" - "}, StringSplitOptions.RemoveEmptyEntries)[0];
sentence = sentence.Split(new string[]{" - "}, StringSplitOptions.RemoveEmptyEntries)[1].Replace(word, new string('_', word.Length));
Console.WriteLine(sentence);
string answer = Console.ReadLine();
if(answer.ToLower()==word.ToLower())
Console.WriteLine("Correct!");
else
Console.WriteLine("Incorrect!");
}
Result:
I took my ___ for a walk
Correct!
I opened the front ____ of my house
Correct!
you need to ______ an item
Incorrect!