开发者

How to check if text1 contains text2 using vb6?

How to check if text1 contains text2 using vb6 ?

Dim text1 as s开发者_开发技巧tring
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


You can use InStr function like this:

Dim position As Integer

position = InStr(1, stringToSearch, stringToFind)

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


Use InStr:

If InStr(text1, text2) > 0 Then


This should do the trick:

if (InStr(text1, text2) > 0) 

Check http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.80).aspx for special cases (parameters are Nothing, empty strings etc.)


RTM = InStr(1, text1,text2)

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜