+ 1
What is wrong with this piece of code? Need help?
string question = Convert.ToString(Console.ReadLine()); if(!question.Contains("How" || "Where" || "Why" || "When" || "Which")) { Console.WriteLine("Please ask a question."); } Console.WriteLine(question);
6 odpowiedzi
+ 4
MrDevEzeoke
You can store all string in an array and using loop you can check. If any string exist then break the loop.
https://code.sololearn.com/c677tEMtcmNK/?ref=app
+ 5
MrDevEzeoke , what you could do additionally is to spell the "keywords" in lower case:
string[] words = {"how", "where", "why", "when", "which"};
then also convert the input to lower case:
string question = Console.ReadLine().ToLower();
This makes it possible to find "Why" as well as "why" or whatever case is used.
+ 3
MrDevEzeoke
Can Contains accept multiple String?
+ 3
Or starting from the array of keywords you can combine Any() and Contains(). To use Any() you have to include Linq.
if(Keywords.Any(kw => question.Contains(kw)))
+ 3
+ 1
I Am AJ ! No it can't. I guess that answers my question however how would I check for these multiple strings within the inputed question?