我的代码总是返回true,即使它应该是false

时间:2014-03-27 14:20:30

标签: vb.net visual-studio-2010 for-loop contains

我想知道我是否能得到一些帮助使这项工作成为可能。

    DevCon = File.ReadAllText("DevConDump.txt")
    DevID = File.ReadAllText("isLegacy.txt")
    DevCon = DevCon.ToUpper
    DevID = DevID.ToUpper
    Dim words As String() = DevID.Split(New Char() {","c})
    For Count = 0 To words.Length
        If DevID.Contains(words.ElementAt(Count)) = True Then
            MsgBox(DevID.Contains(words.ElementAt(Count)))
            MsgBox(words.ElementAt(Count))
            'RegKey.CreateSubKey("Intel_DEVID")
            'RegKey.SetValue("Intel_DEVID", "isLegacy")
            'RegKey.Close
            MsgBox("isLegacy")
        End If
    Next

DevConDump.txt包含一行文本,其中包含一些信息,告诉我它是什么(在这种情况下,一组字母和数字,例如“DEV_0011”,被无用信息包围。

isLegacy.txt包含一个可以包含的值列表。

当我运行此代码时,即使它检查的值明显错误(例如,如果我将字符串PETER放入其中),它总是返回true,表示该值不存在。

有人能告诉我哪里出错了吗?

VB.NET,VS2010

1 个答案:

答案 0 :(得分:2)

除非我遗漏了DevID和单词包含相同数据的内容:

 Dim words As String() = DevID.Split(New Char() {","c})

所以

 DevID.Contains(words.ElementAt(Count)) = True 

永远是真的。

你有意吗:

DevCon.Contains(words.ElementAt(Count)) = True 
相关问题