【发布时间】:2019-03-23 18:50:45
【问题描述】:
我想查看文本框文本是否是下载的 .txt 文件中的单词之一。
我唯一知道的是我可以使用
if (words.Contains(txtBox.Text),但它会在文本文件中找到任何字母并表现得像文件中的单词一样。
private void btnLogin_Click(object sender, EventArgs e)
{
string accessKeys;
WebClient wc = new WebClient();
accessKeys = wc.DownloadString("http://LinkToTextFile.txt");
if (txtBxAccessKey.Text.Contains(" ") || txtBxAccessKey.Text == string.Empty)
{
MessageBox.Show("Empty");
}
else if (accessKeys.Contains(txtBxAccessKey.Text)) //This is what I need to change to work as intended
{
this.Hide();
Loader frmLoader = new Loader();
frmLoader.ShowDialog();
}
else
{
MessageBox.Show("Access Key Not Found");
}
【问题讨论】:
-
显示一些关于您描述的错误行为的示例:“但它会在文本文件中找到任何字母并表现得像文件中的单词一样”
-
@RistoM 在文本文件中,我在不同的行上有“admin”和“test”这两个词,如果我在文本框中键入字母“a”,那么它将继续加载“frmLoader”
-
@RistoM 在有人输入值之前,该值为空,在这种情况下,我键入字母“a”,它继续显示“frmLoader”,因为文本文件中有一个包含字母“的单词”一个'
-
好的,我看到了问题。我可以在几分钟内为您提供一些解决方案作为答案..
-
@RistoM 好的,谢谢