This function allow to get element of a string "chaine$", Just specify the Id of the element "Offset%", and the operator "Sep$"
Graphics 800,600,0,2
Text 10,10,SSP_GET_Line$("a,b,c,d",1)
Text 10,30,SSP_GET_Line$("a,b,c,d",2)
Text 10,50,SSP_GET_Line$("a,b,c,d",3)
Text 10,70,SSP_GET_Line$("a/b/c/d",4,"/")
Text 10,90,SSP_GET_Line$("a,b,c,d",5)
Text 10,110,SSP_GET_Line$("a,b,c,d,.25",5)
Text 10,130,SSP_GET_Line$("a,b,.25,d",5)
Text 10,150,SSP_GET_Line$("a,b,.25,d",3)
Text 10,170,SSP_GET_Line$("0.02|b|c|d",2,"|")
Text 10,190,SSP_GET_Line$("0.02,b,c,d",1)
Flip
WaitKey
End
Function SSP_GET_Line$(chaine$,Offset%=1,Sep$=",")
If Offset<1 DBG_Nfo "/X\ GetLine Erreur => Offset nul " Return False
ligne$=chaine
LnSize%=Len (ligne)
Local l_var$
Local loc1%
If offset=1
If LnSize>0
loc1=Instr(ligne,Sep)
If loc1=0
l_var$=ligne
Else
l_var$=Left(ligne,loc1-1)
EndIf
DBG_Nfo "/!\ GetLine :"+chaine+"=> "+l_var+" Offset="+offset
Return l_var$
Else
DBG_Nfo "/X\ GetLine Erreur => Chaine vierge "
EndIf
Else
If LnSize%>2
; supprime le premier argument
Local loc2% = 1
loc2%=Instr(ligne$,Sep$)
If loc2%=0
DBG_Nfo "/X\ GetLine Erreur => la chaine '"+chaine$+"' ne contien pas assez '"+offset%+"' arguments!"
Return False
EndIf
Local l_part$ = Right(ligne$,LnSize%-loc2%)
Local lnPart% = LnSize%
; cherche l'offset et retourne la chaine entre 'Sep'
For i = 2 To Offset%
Loc2% = Instr (l_part$,Sep$)
If i=offset%
If loc2% = 0
l_var$=l_Part$
Else
l_var$=Left(l_Part$,loc2%-1)
EndIf
If Len(l_var$)=0
DBG_Nfo "/X\ GetLine Erreur => Retourne une chaine vide"
Return False
Else
DBG_Nfo "/!\ GetLine :"+chaine$+"=> "+l_var$+" Offset="+offset%
Return l_var$
EndIf
EndIf
If loc2%=0 DBG_Nfo "/X\ GetLine Erreur => Offset trop grand " Return False
lnPart% = Len(l_Part$)
l_part$ = Right (l_part$,lnPart%-loc2%)
lnPart% = Len(l_Part$)
Next
Else
DBG_Nfo "/X\ GetLine erreur => nombre de caractere insuffisant ( 3 mini ! ) !"
Return False
EndIf
EndIf
End Function
Function DBG_Nfo(texte$)
DebugLog texte
End Function
|