我有一個小項目,我有一個輸入的句子它有可能爲用戶指定的變化:如何生成一整套字符串操作的組合?
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