Check if string contains space

I'm trying to check if he has a space in it. Doesn't work for me.

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

end if
+4
source share
3 answers

The correct way to check if a string contains a character (or substring) is to use a function InStr(). It will return a unidirectional index of the position within the line where the text was found. Thus, a return value> 0 indicates a successful match. For instance:

If InStr(query, " ") > 0 Then
    ' query contains a space
End If

A function InStr()can also take three or four arguments. If you want to specify a starting index, use the version with three arguments:

If InStr(3, query, " ") > 0 Then
    ' query contains a space at or after the 3rd character
End If

( ), . , , . , , (1):

If InStr(1, query, "A", vbTextCompare) > 0 Then
    ' query contains "a" or "A"
End If
+7

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
0

The best and shortest answer to this question is where you use the Instr function. It can be in the following format:

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

All Articles