Vbscript 检查字符串是否包含空格

Vbscript 检查字符串是否包含空格,vbscript,Vbscript,我正在检查刺是否有空隙。以下内容不适用于我 if (skpwords.contains(lcase(query)) And Mid(query, InStrRev(query, " "))) then end if 您可以使用Ubound分割数组,并检查数组的长度以确定是否存在空格 VBS示例: hi = "What is up" spaces = Ubound(Split(hi, " ")) if (spaces = 0) then Wscript.Echo "No Spaces"

我正在检查刺是否有空隙。以下内容不适用于我

if (skpwords.contains(lcase(query)) And Mid(query, InStrRev(query, " "))) then

end if

您可以使用Ubound分割数组,并检查数组的长度以确定是否存在空格

VBS示例:

hi = "What is up"
spaces = Ubound(Split(hi, " "))
if (spaces = 0) then
    Wscript.Echo "No Spaces"
else
    Wscript.Echo "There are spaces"
end if

检查字符串是否包含字符(或子字符串)的正确方法是使用
InStr()
函数。它将返回字符串中找到文本的位置的基于一的索引。因此,返回值>0表示查找成功。例如:

If InStr(query, " ") > 0 Then
    ' query contains a space
End If
InStr()
函数也可以选择接受三个或四个参数。如果要指定起始索引,请使用三个参数版本:

If InStr(3, query, " ") > 0 Then
    ' query contains a space at or after the 3rd character
End If
如果要执行不区分大小写的搜索(默认为区分大小写),请使用四参数版本。请注意,此函数没有允许您指定区分大小写的三参数版本。如果要执行不区分大小写的搜索,则必须始终提供起始索引,即使要从开头开始搜索(
1
):


最好和最短的答案可能是你在哪里使用Instr功能。这可以是以下格式:

mysentence = "This is a sentence" 
if Instr(mysentence, " ")>0 Then
 'do your stuff here..
else
 ' do else stuff here.. 
End if

帮了大忙+1问与答
mysentence = "This is a sentence" 
if Instr(mysentence, " ")>0 Then
 'do your stuff here..
else
 ' do else stuff here.. 
End if