|
-
Jul 2nd, 2005, 03:14 PM
#1
Thread Starter
Admodistrator
Find InStr: (cant explain)
I wrote this code, that will search in a string in between an opening and closing phrase:
VB Code:
Private Sub Form_Load()
MsgBox FindInStr("||", "::", "Cat alpha Pensi france catarax || alabastar cheese gato faggle :: google cheese")
End Sub
Public Function FindInStr(StrOpening As String, StrClosing As String, lpString As String) As String
Dim x As Integer, y As Integer, InStrStr As String, FinalStr As String
x = InStr(lpString, StrOpening)
x = x + Len(StrOpening)
FinalStr = Mid(lpString, x, Len(lpString) - x)
y = InStr(FinalStr, StrClosing)
InStrStr = FinalStr
FinalStr = Mid(FinalStr, y, Len(FinalStr) - y + 1)
FindInStr = Replace(InStrStr, FinalStr, vbNullString): FindInStr = Trim(FindInStr)
End Function
This will return "alabastar cheese gato faggle"
This also didnt work as i wanted, i didnt want to use replace, but i guess i had to
-
Jul 2nd, 2005, 04:14 PM
#2
Re: Find InStr: (cant explain)
This seems to do the same things without the REPLACE...
Why did you want the REPLACE?
Code:
Private Sub Form_Load()
MsgBox FindInStr("||", "::", "Cat alpha Pensi france catarax || alabastar cheese gato faggle :: google cheese")
End Sub
Public Function FindInStr(StrOpening As String, StrClosing As String, lpString As String) As String
Dim x As Integer, y As Integer, InStrStr As String, FinalStr As String
x = InStr(lpString, StrOpening)
x = x + Len(StrOpening)
y = InStr(x, lpString, StrClosing)
FindInStr = Trim(Mid(lpString, x, (y - x) - 1))
End Function
-
Jul 2nd, 2005, 04:19 PM
#3
Thread Starter
Admodistrator
Re: Find InStr: (cant explain)
i didnt want to use replace
i couldnt figure out how this last bit:
FindInStr = Trim(Mid(lpString, x, (y - x) - 1))
-
Jul 4th, 2005, 10:22 AM
#4
Re: Find InStr: (cant explain)
Check out the LeftRange function I posted in this thread:
VB - Some functions that makes string parsing easier
I use thouse functions in 99% of my applications, very usefull functions...
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
|