Page 1 of 1
Between()
Posted: Mon Mar 11, 2013 5:59 pm
by dobro
a function that an extract recovered between 2 tags, like this
Code: Select all
; between () permet de recuperer une chaine entre 2 autres
Procedure.s Between2(string.s, LString.s, RString.s)
;/ Author : Dr. Dri ( bug fixed )
Protected Between.s, lindex.l, RIndex.l
lindex = FindString(string, LString, 0)
RIndex = FindString(string, RString, lindex+Len(LString))
If lindex And RIndex
lindex + Len(LString)
Between = Mid(string, lindex, RIndex-lindex)
EndIf
ProcedureReturn Between
EndProcedure
MessageRequester("Between","Resultat à afficher : caratères entre Dr et py dans le mot Droopy"+Chr(10)+"Resultat : "+ Between2("Droopy", "Dr", "py"))
MessageRequester("Between2","Resultat à afficher : extraire l'url dans la source href="+Chr(34)+"http://www.purebasic.fr"+Chr(34) +Chr(10)+"Resultat : "+ Between2("href="+Chr(34)+"http://www.purebasic.fr"+Chr(34),"href="+Chr(34),Chr(34))); EPB
Re: Between()
Posted: Mon Mar 11, 2013 7:27 pm
by Danilo
between() is better used for numbers IMO, like min() and max().
Code: Select all
Procedure between(var,num1,num2)
If var >= num1 And var <= num2
ProcedureReturn #True
EndIf
EndProcedure
[...]
If between(Event,0,#WM_USER-1)
msg$ = "SYSTEM MESSAGE: " : Continue
ElseIf between(Event,#WM_USER,$7FFF)
msg$ = "#WM_USER MESSAGE: " : ;Continue
ElseIf between(Event,#WM_APP ,$BFFF)
msg$ = "#WM_APP MESSAGE: "
ElseIf between(Event,$C000,$FFFF)
msg$ = "STRING MESSAGE (RegisterWindowMessage): "
Else
msg$ = "RESERVED BY SYSTEM MESSAGE: "
EndIf
You have another name for your string function? InStr()? InString()? ExtractString()?
Re: Between()
Posted: Mon Mar 11, 2013 7:52 pm
by dobro
the name really matter to me, the most important is the function

Re: Between()
Posted: Mon Mar 11, 2013 8:30 pm
by Joris
Maybe ExtractRegularExpression() can be a bit of help ?
Re: Between()
Posted: Mon Mar 11, 2013 8:30 pm
by skywalk
In the meantime, I use this...
It allows empty strings for the left and right and returns the 'Position After' the found search for further processing.
Code: Select all
Procedure.s SF_Between(SearchIn$, From$, sTo$, *PosAfter.Integer=0, StartPos.i=1)
; REV: 110519, skywalk
; PB 4.6 FindString() added default StartPos and accepts <=0 entries without error.
; REV: 120409, skywalk
; Allow From$ = "" to start from 1st character.
; Allow sTo$ = "" to stop at last character.
; Return = string between 2 multi-char delimiters
; *PosAfter = Text position after found String
; Syntax:
; Debug SF_Between("<html>some text here</html>", "<html>", "</html>")
; Debug SF_Between(r, "some", " ", @PosAfter, StartPos)
Protected.i nLen1, nLen2, nLen, nLen3
Protected.s Found$
If From$
nLen1 = FindString(SearchIn$, From$, StartPos)
Else
nLen1 = 1
EndIf
If nLen1
If sTo$
nLen2 = FindString(SearchIn$, sTo$, nLen1 + Len(From$))
Else
nLen2 = Len(SearchIn$) + 1
EndIf
If nLen2
nLen = nLen1 + Len(From$)
nLen3 = nLen2 - nLen
Found$ = Mid(SearchIn$, nLen, nLen3)
If (nLen + nLen3 > 0) And *PosAfter ; Avoid Null Pointer error
*PosAfter\i = nLen2 ;+ 1 ; used to be -> nLen
EndIf
EndIf
EndIf
ProcedureReturn Found$
EndProcedure
Define.i PosAfter
Define.s s$ = "<html>some text here</html>"
Debug Len(s$)
Debug SF_Between(s$, "<html>", "</html>", @PosAfter) + ", nextpos = " + Str(PosAfter)
Debug SF_Between(s$, "", "</html>", @PosAfter) + ", nextpos = " + Str(PosAfter)
Debug SF_Between(s$, "<html>", "", @PosAfter) + ", nextpos = " + Str(PosAfter)
Debug SF_Between(s$, "", "", @PosAfter) + ", nextpos = " + Str(PosAfter)
Re: Between()
Posted: Mon Mar 11, 2013 11:07 pm
by dobro
Thank you, though, I was not looking for a solution,
I suggested simply that'll be good, a function like this existed in PureBasic
