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
:bigyello:
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
Re: Find InStr: (cant explain)
Quote:
i didnt want to use replace
i couldnt figure out how this last bit:
FindInStr = Trim(Mid(lpString, x, (y - x) - 1))
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...