我想創建一個字符串,下面是我想實現的東西:我想創建最終的字符串這樣拆分和合並兩個不同的字符串
String first = "Previous.value1 | Previous.value2";
String second = "New.value1| New.value2";
:
string final ="generate Previous.value1 cross New.value1 ? Previous.value1 cross New.value2";
但問題是,當我將有不匹配象下面這樣:
String first = "Previous.value1 | Previous.value2";
String second = "New.value1";
然後我想有這樣的,因爲我沒有匹配值Previous.Value2在第二個變量:
string final ="generate Previous.value1 cross New.value1";
到目前爲止,我成功我在最後生成字符串時,我在的價值相同的計數這兩個字符串。
string final = "generate";
if (first.Split('|').Count() - second.Split('|').Count() == 0)
{
int i = 0;
foreach (var item in first.Split('|').Count())
{
if (i == 0)
final = final + item + " cross " + second.Split('|')[i];
else
final = final + " ? " + item + " cross " + second.Split('|')[index];
i++;
}
}
那麼是什麼問題? – PMerlet
if(second.Contains(「|」)){//做點什麼} –
@TimSchmelter:我已經更新了我的問題的變化。好吧 –