c# - 如何通过after从网站的每一行(DownloadString)获取数据:char并停止直到;字符
问题描述
我使用 WebClient 和 DownloadString 将 RAW 文本文件转换为字符串,并且我想获得第一个单词,就像之前的每一件事一样: char 转换为字符串,以及之后的内容:但之前;在其他字符串中。在这种情况下,我希望 word111 和 floor271 位于单独的字符串中,而 table123 和 fan891 则位于另一个字符串中。
文本文件如下所示:
word111:table123;
floor271:fan891;
我已经尝试环顾了好几天,因为我在代码中使用 Contains 方法来查看整行文本是否有时匹配,例如 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 */
}
我希望代码不适用于拆分,因为它可以通过 : 和 ; 拆分字符串 字符,但我不希望用户名和密码在同一字符串中可见。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
}
推荐阅读
- mongodb - 仅填充猫鼬中的特定字段
- python - PLS 的结果随 sci-kit 版本而变化
- c# - 我可以使用 DotNetBrowser 仅将一个 DomElement 保存到 jpg 吗?
- html - 无法在 Angular 2 中将 HTML 图像和画布标签下载为 PDF
- sql - Oracle 9.i 从两张表和三条记录中选择结果一条记录
- android - 检查位置图层是否已更改。Yandex MapKit 3.0
- python - 根据值使句子/单词复数
- asp.net-core - IStringLocalizer 与 resource.designer.cs
- android - 在 AOSP 中构建 framework.jar
- python - 检查数据类字段是否具有默认值的 Pythonic 方法