c# - How stop string.Contains() picking out a word that is within another word. Better explanation below -
i using speech recognition in program , make easier writing out every possible combination of words execute command, using .contains function pick out keywords. example...
private void speechhypothesized(object sender, speechhypothesizedeventargs e) { string speech = e.result.text; if (speech.contains("next") && speech.contains("date")) { messagebox.show(speech + "\nthe date 11th"); } else if (speech.contains("date")) { messagebox.show(speech + "\nthe date 10th"); } }
as can see, if speech recognized, display text box saying hypothesized , date. however, when @ speech displayed in text box, things "next update". so, program looking 1 word within i.e. "date" inside of "update". not want happen otherwise won't accurate, how can make .contains method pick out word on it's own, , not inside other words? thanks
alternative solution, split spaces , check keywords
string speech_text = e.result.text; string[] speech = speech_text.split(); if (speech.contains("next") && speech.contains("date")) { messagebox.show(speech_text + "\nthe date 11th"); } else if (speech.contains("date")) { messagebox.show(speech_text + "\nthe date 10th"); }
Comments
Post a Comment