所以由于某种原因,我尝试使用Replace,但效果不佳:
if (counter >= Type.Count)
{
counter = 0;
}
NewTxT.Add(Type[counter].Replace("KW", Keyword[rnd.Next(0, Keyword.Count)])
.Replace("PT", PageType[rnd.Next(0, PageType.Count)])
.Replace("NW", Keyword2[rnd.Next(0, Keyword2.Count)]
.Replace("PF", PageFormat[rnd.Next(0, PageFormat.Count)])
.Replace("DE", Domains[rnd.Next(0, Domains.Count)])
.Replace("SF", SearchFunction[rnd.Next(0, SearchFunction.Count)])));
counter++;
这是我需要替换的:
SFKW.PT?PF= + SFKW
由于某种原因,它取代了
KW, PT
但是它不能代替SF和PF ...
我已经尝试修复了好几个小时,但我找不到发生这种情况的原因
答案 0 :(得分:3)
重新格式化此代码将使其更加清晰,并且在一定程度上可以清楚地看出问题所在-您将结束)
放在错误的位置:
if (counter >= Type.Count) counter = 0;
NewTxT.Add(Type[counter]
.Replace("KW", Keyword[rnd.Next(0, Keyword.Count)])
.Replace("PT", PageType[rnd.Next(0, PageType.Count)])
.Replace("NW", Keyword2[rnd.Next(0, Keyword2.Count)] // <-- There's a missing ")" here...
.Replace("PF", PageFormat[rnd.Next(0, PageFormat.Count)])
.Replace("DE", Domains[rnd.Next(0, Domains.Count)])
.Replace("SF", SearchFunction[rnd.Next(0, SearchFunction.Count)]))); // <-- ...and one too many here
counter++;
因此,以下应执行您想要的操作:
if (counter >= Type.Count) counter = 0;
NewTxT.Add(Type[counter]
.Replace("KW", Keyword[rnd.Next(0, Keyword.Count)])
.Replace("PT", PageType[rnd.Next(0, PageType.Count)])
.Replace("NW", Keyword2[rnd.Next(0, Keyword2.Count)])
.Replace("PF", PageFormat[rnd.Next(0, PageFormat.Count)])
.Replace("DE", Domains[rnd.Next(0, Domains.Count)])
.Replace("SF", SearchFunction[rnd.Next(0, SearchFunction.Count)]));
counter++;