如何使用vb6检查text1是否包含text2?

far*_*oft 13 vb6

如何使用vb6检查text1是否包含text2?

Dim text1 as string
Dim text2 as string

text1 = "hello world I am Anas"
text2 = "Anas"

if (check if text2 is in text1) 'the result should be true or false
Run Code Online (Sandbox Code Playgroud)

Sar*_*raz 27

你可以使用这样的InStr函数:

Dim position As Integer

position = InStr(1, stringToSearch, stringToFind)

If position > 0 Then
  ' text is inside
Else
  ' text is not inide 
End If
Run Code Online (Sandbox Code Playgroud)


Ode*_*ded 15

用途InStr:

If InStr(text1, text2) > 0 Then
Run Code Online (Sandbox Code Playgroud)

  • +1但为什么不链接到Instr的VB6手册条目http://msdn.microsoft.com/en-us/library/aa445031(v=VS.60).aspx (2认同)

Lar*_*sbj 5

这应该做的伎俩:

if (InStr(text1, text2) > 0) 
Run Code Online (Sandbox Code Playgroud)

检查http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.80).aspx在特殊情况下(参数都没什么,空字符串等)