【发布时间】:2026-01-09 11:15:02
【问题描述】:
我正在制作控制台 c# 应用程序,它实际上从 text1 中获取所有行,并在每行的末尾附加一个文本“.php?”或“.html?这些文本也是来自 text2 的行,我想在 text1 的每一行末尾打印 text2 中的第一个。然后在 text2 中取第二个并执行相同操作,直到它完成 text2?
这是我的代码:
string[] resultConfig = File.ReadAllLines("keywords.txt");
string[] readParameters = File.ReadAllLines("param.txt");
for (int i = 0; i < readParameters.Length; i++)
{
for (int x = 0; x < resultConfig.Length ; x++)
{
resultConfig[x] = resultConfig[x] + readParameters[i];
Console.WriteLine(resultConfig[x]);
}
}
输出: **
keyboards.php?.html?.asp?
karachi.php?.html?.asp?
keychain.php?.html?.asp?
in khobar.php?.html?.asp?
lebanon.php?.html?.asp?
lights.php?.html?.asp?
london.php?.html?.asp?
must have.php?.html?.asp?
**
**
WHAT IT SHOULD BE:
keyboards.php?
karachi.php?
keychain.php?
in khobar.php?
lebanon.php?
lights.php?
london.php?
must have.php?
keyboards.html?
karachi.html?
keychain.html?
in khobar.html?
lebanon.html?
lights.html?
london.html?
must have.html?
** 等等……
** KEYWORDS.TXT 包含 **
keyboards
karachi
keychain
in khobar
lebanon
lights
london
must have
** PARAM.TXT 包含 **
.php?
.asp?
.html?
【问题讨论】:
-
你能提供一个你的
keywords.txt和param.txt的例子吗? -
我加了检查一下
-
您将无法向数组添加比初始化时更多的项目(看来您希望将
resultConfig的大小增加 3 倍)。您可能想改用List<string>。 -
如何将结果保存在文本文件中?