我有一个小项目,我有一个输入的句子它有可能为用户指定的变化:如何生成一整套字符串操作的组合?
The {small|big} car is {red|blue}
上面是一个例句我想分成4个句子,像这样:
- 的小型车是红色的
- 大汽车是红色的
- 的小型车是蓝色
- 大汽车是蓝色
我似乎无法绕过这个问题。也许有人可以帮我。
编辑 这是我最初的代码
Regex regex = new Regex("{(.*?)}", RegexOptions.Singleline);
MatchCollection collection = regex.Matches(richTextBox1.Text);
string data = richTextBox1.Text;
//build amount of variations
foreach (Match match in collection)
{
string[] alternatives = match.Value.Split(new char[] { '|', '{', '}' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string alternative in alternatives)
{
//here i get problems
}
}
你尝试过这么远吗? ([提示](http://msdn.microsoft.com/en-us/library/ch45axte.aspx)) – 2011-03-22 14:06:05
你看过正则表达式吗? – 2011-03-22 14:07:48
您错过了作业标签吗? – 2011-03-22 14:08:41