//private void Onload(object sender, EventArgs e) //{ // TestTextbox.Text = "home"; // Choices commands = new Choices(); // commands.Add(new string[] { "hello", "hey", "jarvis" }); // GrammarBuilder gBuilder = new GrammarBuilder(); // gBuilder.Append(commands); // Grammar grammar = new Grammar(gBuilder); // recEngine.LoadGrammarAsync(grammar); // recEngine.SetInputToDefaultAudioDevice(); // recEngine.SpeechRecognized += recEngine_SpeechRecognized; // void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { // switch (e.Result.Text) // { // case "hello": // MessageBox.Show("hi handsome how are you"); // break; // case "hey": // TestTextbox.Text = ("hey what you doing"); // break; // } // } public void PrintCityState(CityState cs) { if (cs.City != null) { city = cs.City; state = cs.StateName; //TestTextbox.Text = city + " + " + state; /*cs.City +" "+ cs.StateAbbreviation + " " + cs.StateName; */ } // Console.WriteLine("{0}, {1} ({2})", cs.City, cs.StateAbbreviation, cs.StateName); }
public static CityState GetCityState(string input) { string truncatedInput = input; var statesDictionary = new Dictionary <string, string> { { "GE", "Germany" }, { "EN", "England" }, { "SP", "Spain" }, { "FR", "France" }, { "IT", "Italy" }, { "PK", "Pakistan" }, { "IN", "India" }, { "RU", "Russia" } // And so forth for all 50 states }; var cityState = new CityState(); foreach (KeyValuePair <string, string> kvp in statesDictionary) { if (input.Trim().ToLower().EndsWith(" " + kvp.Key.ToLower())) { cityState.StateName = kvp.Value; cityState.StateAbbreviation = kvp.Key; truncatedInput = input.Remove(input.Length - 1 - kvp.Key.Length); break; } if (input.Trim().ToLower().EndsWith(" " + kvp.Value.ToLower())) { cityState.StateName = kvp.Value; cityState.StateAbbreviation = kvp.Key; truncatedInput = input.Remove(input.Length - 1 - kvp.Value.Length); break; } } cityState.City = truncatedInput.Trim().Trim(',').Trim(); return(cityState); }