如何通过以下方式从网站的每一行(下载字符串)获取数据:char并停止直到;char



我使用WebClient和DownloadString将RAW文本文件放入字符串中,我想获取第一个单词,就像之前的每个单词:char到字符串中,以及之后的内容:但在之前;在其他字符串中。在这种情况下,我希望 word111 和 floor271 在单独的字符串中,而 table123 和 fan891 放在另一个字符串中。

文本文件如下所示:

word111:table123;
floor271:fan891;

几天来,我试图环顾四周,因为我在代码中使用 Include 方法来查看整行文本有时是否匹配,例如 word111:table123;如果原始文本文件中存在,则代码将继续。我看了 Split、IndexOf 和类似的东西,但我不明白它们是否能实现这一目标,因为我需要每一行/每一行,而不仅仅是一行。

WebClient HWIDReader = new WebClient();
string HWIDList = HWIDReader.DownloadString("/*the link would be here, can't share it*/");
if (HWIDList.Contains(usernameBox.Text + ":" + passwordBox.Text))
{
/* show other form because username and password did exist */
}

我希望代码不适用于 Split,因为它可以通过 : 和 ; 字符拆分字符串,但我不希望用户名和密码在同一字符串中可见。IndexOf 将删除指定字符之前或之后的内容。(也许可以使用 IndexOf 来两种方式?从 : 直到 ; 这可能吗,以及如何?(提前谢谢你。

您可以根据换行符拆分字符串。

string HWIDList = HWIDReader.DownloadString("/*the link would be here, can't share it*/");
string[] lines = HWIDList.Split('n');
// NOTE: Should create a hash from the password and compare to saved password hashes 
// so that nobody knows what the users' passwords are
string userInput = string.Format("{0}:{1};", usernameBox.Text, passwordBox.Text);
foreach (string pair in lines)
{
if (pair != userInput)
continue;
// found match: do stuff
}

最新更新