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

时间:2010-12-31 16:22:24

标签: 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

4 个答案:

答案 0 :(得分:24)

您可以使用InStr这样的功能:

Dim position As Integer

position = InStr(1, stringToSearch, stringToFind)

If position > 0 Then
  ' text is inside
Else
  ' text is not inide 
End If

答案 1 :(得分:15)

使用InStr

If InStr(text1, text2) > 0 Then

答案 2 :(得分:5)

这应该可以解决问题:

if (InStr(text1, text2) > 0) 

检查http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.80).aspx是否有特殊情况(参数为Nothing,空字符串等)

答案 3 :(得分:2)

RTM = InStr(1, text1,text2)

if RTM > 0 then debug.print "Text2 was found at position: "; RTM
相关问题