【发布时间】:2020-08-26 03:36:34
【问题描述】:
我想将一个文本文件的多个字符串分别拆分为两个字符串(例如:car;driver)。我不知道如何将第一个单词放在array1 中,将第二个单词放在array2 中。因此,我尝试使用分号的 if 查询将 word1 的每个字母放入 array1 中,并与第二个单词相同,以便稍后将它们重新组合到单词中。
但我认为我所做的事情太复杂了,我现在卡住了,哈哈。
这里展示我的一段代码:
private void BtnShow_Click(object sender, EventArgs e)
{
LibPasswords.Items.Clear();
string path = "passwords.txt";
int counter = 0;
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
using (StreamReader reader = new StreamReader(fs))
{
while (reader.ReadLine() != null)
{
counter++;
}
//for (int i = 0; i < counter; i++)
//{
// var Website = reader.ReadLine().Split(';').Select(x => new String[] { x });
// var Passwort = reader.ReadLine().Split(';').Select(y => new String[] { y });
// LibPasswords.Items.Add(String.Format(table, Website, Passwort));
//}
string[] firstWord = new string[counter];
string[] lastWord = new string[counter];
int i = 0;
int index = 0;
while (reader.Peek() >= 0)
{
string ch = reader.Read().ToString();
if (ch != ";")
{
firstWord[i] = ch;
i++;
}
else
{
index = 1;
}
while (reader.Peek() >= 0)
{
??????????????????????????????????
}
}
}
}
对不起,我的英语不是我的母语。
【问题讨论】: