|
-
Dec 3rd, 2002, 01:58 AM
#1
Thread Starter
Addicted Member
Finding a string between two words
Hello all,
I would like to be able to find out what is in the textbox between the words QQQ1 and QQQ2, however I am not sure how to do this. The code I tried to do it with is...
VB Code:
Public Sub TrimString(TheString As String, KeepAfter As String, KeepBefore As String)
Dim posA As Long
Dim posB As Long
posA = 1
posB = 1
Dim incTill As Long
incTill = Len(TheString) - Len(KeepAfter)
Debug.Print incTill & " is intill"
For i = 1 To incTill
If Mid(TheString, posA, Len(KeepAfter)) = KeepAfter Then
Debug.Print posA
GoTo FoundKeepAfter
posA = i
End If
Next
TheString = "Cannot find KeepAfter"
Exit Sub
FoundKeepAfter:
incTill = Len(TheString) - Len(KeepBefore)
For j = 1 To incTill
If Mid(TheString, posB, Len(KeepBefore)) = KeepBefore Then
GoTo FoundKeepBefore
posB = j
End If
Next
TheString = "Cannot find KeepBefore"
Exit Sub
FoundKeepBefore:
TheString = Mid(TheString, posA, posA - posB)
DoEvents
Text1.Text = TheString
End Sub
Private Sub Command1_Click()
TrimString Text1.Text, "QQ1", "QQQ2"
End Sub
But it doesnt work Is there some good way to do it?
Thanks
-
Dec 3rd, 2002, 03:02 AM
#2
Hyperactive Member
VB Code:
Dim strSearch1 As String
Dim strSearch2 As String
Dim Q1Pos As Integer
Dim Q2Pos As Integer
Dim strMid As String
strSearch1 = "This is blahQQQ1You cannot find meQQQ2"
Q1Pos = InStr(1, strSearch1, "QQQ1")
Q2Pos = InStr(1, strSearch1, "QQQ2")
strMid = Mid(strSearch1, Q1Pos + 4, Q2Pos - Q1Pos - 4)
MsgBox strMid
strSearch2 = "QQQ1You cannot find meQQQ2"
Q1Pos = InStr(1, strSearch2, "QQQ1")
Q2Pos = InStr(1, strSearch2, "QQQ2")
strMid = Mid(strSearch2, Q1Pos + 4, Q2Pos - Q1Pos - 4)
MsgBox strMid
PS: I did not run thru your code, BUT your are invoking the
TrimString Text1.Text, "QQ1", "QQQ2" routine. Should the 1st parameter not be QQQ1"?
-
Dec 3rd, 2002, 04:10 AM
#3
Thread Starter
Addicted Member
thanks
THANKS! That works great for me, and I also understand it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|