/// <summary> /// Creates a new QuestionData based on the specified input text. /// </summary> /// <param name="input">The input text to get a match for. For example, "How many newspapers can Brenda deliver in 9 hours?".</param> /// <returns>Returns the new QuestionData, or null if a no matches were found for the specified input.</returns> public static QuestionData Create(string input) { const string pattern = @"(?<question>[+-]?((\d+(\.\d+)?))\s*\w+)"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); if (matches.Count == 0) { return(null); } QuestionData questionData = new QuestionData(); questionData.question = RegexHelper.GetValue <string>(matches, "question"); return(questionData); }
private void btnPaste_Click(object sender, RoutedEventArgs e) { if (Clipboard.ContainsText(TextDataFormat.Html)) { string htmlText = Clipboard.GetText(TextDataFormat.Html); //System.Xml.Linq.XDocument xDocument = System.Xml.Linq.XDocument.Load(GenerateStreamFromString(htmlText)); } string text = Clipboard.GetText(); FactQuestion factQuestion = FactQuestion.Create(text); QuestionData questionData = QuestionData.Create(factQuestion.Question); ValueUnits data1, data2, question; double data1Value, data2Value, questionValue; try { GetQuestionData(factQuestion.Fact, questionData.question, true, out data1, out data2, out question, out data1Value, out data2Value, out questionValue); } catch (Exception ex) { ShowError(ex); return; } NoErrors(); changingInternally = true; try { tbxQuestion.Text = factQuestion.Question.Replace(question.value, questionValue.ToString()) + '?'; tbxFact.Text = factQuestion.Fact.Replace(data1.value, data1Value.ToString()).Replace(data2.value, data2Value.ToString()) + '.'; } finally { changingInternally = false; } AnswerQuestion(); }