If i'm using the GetStringBetween function how can i make it move to the next line with the start and end val? for example: <img src="google.com/page1"> <img src="google.com/page2"> and i want it to tell me what's in between google.com/ and the last " how would i have it tell me page1 and then loop back through and tell me page2? i know the for i= lbound to ubound thing i mean have the function go to the next line of the source. thanks in advanced
Basically what you are doing is searching a string for a smaller string, it return's the char position of what you are searching for so instead of starting at the beginning you need to make it start from where your search ended. not that difficult.. So... This need some changes(just to the function declaration) but it should give you a good idea of what is needed... Code (Text): Dim LastResult As String Public Function ForEach(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String Dim Result = "" Dim LastResult As String = "" Dim A = InStr(1, Source, Start) + Len(Start) Do Until Result = "" If A = 0 Then Result = "" Return Result Else Dim B = InStr(A, Source, Finish) If B = 0 Then Result = "" Return Result Else Result = Mid(Source, A, B - A) Return Result LastResult = Result A = InStr(B, Source, Start) + Len(Start) End If End If Loop End Function
I've tried using your code to adapt mine to yours but whenever i try to use it nothing happens, i hit my command button and the program just sits there, it doesn't even act like it's working. Also what is the code you put up in? i'm using vb6 and a lot of the functions you used don't work with vb6...
Here to make life easy as possible for you.. Code (Text): Public Function ExtractAll(SearchString As String, StartString As String, EndString As String, AddToList As ListBox) As String Dim Temp As Long, temp1 As Long, temp2 As Long, temp3 As Long temp1 = 1 Do While InStr(temp1, SearchString, StartString, vbTextCompare) <> 0 Temp = InStr(temp1, SearchString, StartString, vbTextCompare) + Len(StartString) temp2 = InStr(Temp, SearchString, EndString, vbTextCompare) temp3 = temp2 - Temp temp1 = temp2 + 1 AddToList.AddItem (Mid$(SearchString, Temp, temp3)) Loop End Function
i understand what i need to do and what the code is doing(that's the code i've been using), looking through your first code really helped me understand what i needed to do, its just i'm having trouble applying it to the code. What happens when i try to add the loop is either it doesn't do anything at all when i click my command button or it just gives me tons of blank spaces. I wasn't trying to ask for the exact code, i'm sorry if that's what it sounded like, but i'm just having trouble applying what you've said i should do. Code (Text): Public Function GetStringBetween(ByVal InputText As String, _ ByVal StartText As String, _ ByVal EndText As String, _ Optional ByVal StartPosition = 1) As String Dim lnTextStart As Long Dim lnTextEnd As Long Do Until GetStringBetween = "" lnTextStart = InStr(StartPosition, InputText, StartText, vbTextCompare) + Len(StartText) lnTextEnd = InStr(lnTextStart, InputText, EndText, vbTextCompare) If lnTextStart >= (StartPosition + Len(StartText)) And lnTextEnd > lnTextStart Then GetStringBetween = Mid$(InputText, lnTextStart, lnTextEnd - lnTextStart) StartPosition = lnTextEnd Else GetStringBetween = "" End If Loop End Function this is what i've changed it to and i know i'm probably using what you said too directly but from what i gather it only needs the one loop to have it go back around and search again from the end of the last search the StartPosition = lnTextEnd and it needs to do that until the GetStringBetween="" and i know its proabably not quite as simple as that but that's what i've gathered from looking at your code and trying to use what you told me...
Well this is in .net but it works and you should get the idea here. Code (Text): Public Function GetAll(ByRef Source As String, ByRef Start As String, ByRef Finish As String, ByVal myListbox As ListBox, Optional ByRef iStart As Integer = 0) As String Dim iFinish As Integer Dim Result As String Dim FoundAll As Boolean = False iStart = InStr(1, Source, Start) + Len(Start) Do While iStart > 0 Result = String.Empty iFinish = InStr(iStart, Source, Finish) If iFinish = 0 Then FoundAll = True End If Result = Mid(Source, iStart, iFinish - iStart) iStart = InStr(iFinish, Source, Start) + Len(Start) SetText(ListBox_Items, Result) If InStr(iStart, Source, Start, CompareMethod.Binary) = 0 Then Exit Do End If Loop End Function
add theses two functions Public Function ParseRight(What As String, StopAt As String) As String On Error GoTo PErr ParseRight = Mid(What, InStr(What, StopAt) - 1) Exit Function PErr: ParseRight = "Search string does not exist" End Function Public Function ParseLeft(What As String, StopAt As String) As String On Error GoTo PErr ParseLeft = Left(What, InStr(What, StopAt) - 1) Exit Function PErr: ParseLeft = "Search string does not exist" End Function so do this: newtext.text = Parseright(text.text, "src=") newtext.text = parseleft(newtext.text, "img src") whatyouwant.text = getbetween(newtext.text, ".com/", ">") whatyouwant.text = Replace(whatyouwant.text, ",", "") thatll get you page1 newtext2.text = Parseright(text2.text, ".com") whatyouwant.text = getbetween(newtext.text, ".com/", ">") whatyouwant.text = Replace(whatyouwant.text, ",", "") that should get you page 2 tell me how it goes
Thanks for the help Snowmann but i had already figured it out... i really appreciate your trying to help though