Function subStr$(iStr$,pos,token$=" ",quotes=1,all=0)
Local sStart
Local sSpace
Local fQuote
Local eQuote
Local sub
Local sSub$
Local lStart
Local lLen
Local lQuote
If (iStr$ = "") Then
Return ""
EndIf
If (pos < 1) Then
Return
EndIf
While (sub < pos)
sub = sub + 1
If (sStart+1 > Len(iStr$)) Then
Return ""
EndIf
sSpace = Instr(iStr$,token$,sStart+1)
fQuote = Instr(iStr$,Chr$(34),sStart+1)
If ((Not sSpace) And (Not fQuote)) Then
If (sub < pos) Then
Return ""
Else
Return Mid$(iStr$,sStart+1,Len(iStr$)-sStart)
EndIf
EndIf
If ((fQuote > 0) And (fQuote < sSpace) And (quotes=1)) Then
eQuote = Instr(iStr$,Chr$(34),fQuote+1)
If (Not eQuote) Then
Return ""
EndIf
sSub$ = Mid$(iStr$,fQuote+1,(eQuote-fQuote)-1)
lStart = fQuote+1
lQuote = 1
sStart = eQuote+1
ElseIf ((fQuote > 0) And (Not sSpace) And (quotes=1)) Then
eQuote = Instr(iStr$,Chr$(34),fQuote+1)
If (Not eQuote) Then
Return ""
EndIf
sSub$ = Mid$(iStr$,fQuote+1,(eQuote-fQuote)-1)
lStart = fQuote+1
lQuote = 1
sStart = eQuote+1
Else
sSub$ = Mid$(iStr$,sStart+1,(sSpace-sStart)-1)
lStart = sStart
lQuote = 0
sStart = sSpace
EndIf
Wend
If (all = 1) Then
If (lQuote = 1) Then
lLen = Len(iStr$)
If (lLen-lStart > 0) Then
Return Mid$(iStr$,lStart,lLen-lStart)
Else
Return ""
EndIf
Else
lLen = Len(iStr$)
If (lLen-lStart > 0) Then
Return Right$(iStr$,lLen-lStart)
Else
Return ""
EndIf
EndIf
EndIf
Return sSub$
End Function
Similiar function that I use - think it all works properly but long time since I played with it.
|