String 输入框包含特定的单词

String 输入框包含特定的单词,string,vbscript,String,Vbscript,如何检查输入是否包含特定字符?例如,如果我有: word = inputbox("What time is it?") 例如,如何检查输入是否包含数字“7”?我见过InStr函数,但我不知道该由谁来使用它。这是正确的使用方法吗?我不在乎那部分 您可以使用此选项检查更新的: if InStr(1, word, "7", vbTestCompare) then msgbox "You typed something with 7 in it." elseif not InStr(1, word

如何检查输入是否包含特定字符?例如,如果我有:

word = inputbox("What time is it?")
例如,如何检查输入是否包含数字“7”?我见过InStr函数,但我不知道该由谁来使用它。这是正确的使用方法吗?我不在乎那部分


您可以使用此选项检查更新的:

if  InStr(1, word, "7", vbTestCompare) then
msgbox "You typed something with 7 in it."

elseif not InStr(1, word, "7", vbTestCompare) then
msgbox "You did not type something with 7 in it."

end if

你可以使用它,就像用InStr检查任何字符串一样。InputBox函数返回一个字符串,因此是的,这应该可以工作。这是你的问题还是你得到了错误或意外的结果?老实说,这个示例代码没有多大意义,可以更好地结构化。可能是重复的是的,我只是想知道如何使用这个函数,但我现在明白了。这只是一段代码,我还在做。只有当7是唯一输入到输入框中的东西时,这才有效。我想知道如果我在晚上7:30输入,是否有一个7。显示了对布尔逻辑的严重误解。我对vbTestCompare的功能感到困惑。我看过MSDN,但仍然不完全理解。
if  InStr(1, word, "7", vbTestCompare) then
msgbox "You typed something with 7 in it."

elseif not InStr(1, word, "7", vbTestCompare) then
msgbox "You did not type something with 7 in it."

end if