C# 我需要在C中使用多个模式作为输入进行模式匹配

C# 我需要在C中使用多个模式作为输入进行模式匹配,c#,linq,C#,Linq,我需要做一些模式匹配来处理一系列问题,并提出 一些将在解决方案列表中占据首位的语句。我需要匹配的每个问题 第一句以?结尾?。例如,如果具有以下字符串: input="Which of the following can be aa ... zz?" 然后我需要看看它是否匹配一些预定义的模式,如果匹配,那么我需要填充两个变量。在本例中,上面的字符串需要产生以下结果: string1= "Can be aa ... zz:" string2= "Cannot be contained aa ...

我需要做一些模式匹配来处理一系列问题,并提出 一些将在解决方案列表中占据首位的语句。我需要匹配的每个问题 第一句以?结尾?。例如,如果具有以下字符串:

input="Which of the following can be aa ... zz?"
然后我需要看看它是否匹配一些预定义的模式,如果匹配,那么我需要填充两个变量。在本例中,上面的字符串需要产生以下结果:

string1= "Can be aa ... zz:"
string2= "Cannot be contained aa ... zz:"
其中文本aa。。。源中的zzz显示在目标中

Inputs:

1 - Which of the following can be aa ... zz?
2 - Which of the following are correct?
3 - What will result when aa ... zz?
4 - Which of the following is a aa ... zz?
5 - Which are aa ... zz?
6 - What can be said about aa ... zz:
7 - Which of the following is true?
8 - What will be the result when aa ... zz?

Output 1:

1 - Can be aa ... zz:
2 - Correct:
3 - The following will result::
4 - A aa ... zz
5 - The following are aa ... zz
6 - True statement(s)
7 - True statement(s)
8 - The following will result:

Output 2:

1 - Cannot be aa ... zz:
2 - Incorrect:
3 - The following will not result
4 - Not a aa ... zz:
5 - Are not aa ... zz:
6 - False statement(s)
7 - False statement(s)
8 - The following will not result
我在想,我应该将输入模式和输出模式存储在一个参考数据类中,然后结合使用链接和模式匹配

有人有什么建议吗。即使我能看到如何进行一场比赛,那也很好。 如果我有一个例子,那么我可以编写更多的代码,并从中工作

什么样的模式模式就是文本。例如,我想看看我的输入字符串是否以以下哪项开始,以?结束


这些问题来自哪里一组有限的问题。如果我无法获得匹配,那么我将在输出中输入True或False之类的内容。

它可以按如下方式建模:

static Tuple<string,string> Match(string question)
{
   //Do the matching and return the string,string tuple where first 
   //string is for output 1 and second for output 2.
}

static Tuple<List<string>,List<string>> GetOutput(List<string> questions)
{
    var r = questions.Select(q => Match(q));
    return new Tuple<List<string>,List<string>(r.Select(t => t.Item1).ToList(), r.Select(t =>  t.Item2).ToList());
}

什么样的图案?你在用什么,正则表达式?这些问题从何而来,是一组有限的可能值,还是你在解析书籍?再详细一点,任何你已经需要处理的事情都可能会有所帮助。谢谢你的评论。我在问题上又加了一些注释。希望能有帮助。我只是想找一个简单的建议,让我开始。但这不是只适用于精确匹配吗?我想我需要用一些像regex这样的东西作为aa。。。我的字符串的zz部分可以是任何序列,但以结尾的部分除外?是的,在匹配函数中可以使用substring或regex来查找适当的模式