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

16

如何使用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个回答

32
你可以像这样使用InStr函数:
Dim position As Integer

position = InStr(1, stringToSearch, stringToFind)

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

16

使用InStr函数:

If InStr(text1, text2) > 0 Then

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

5

1
你正在链接到vb.net,而不是vb6。 - Oded

2
RTM = InStr(1, text1,text2)

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接