Page 1 of 1

StringField better

Posted: Wed Dec 22, 2004 11:37 am
by dom
Code updated For 5.20+

it's code i am use all time...

Code: Select all

Procedure.s stringfield2(var$,indice,p$)
lp=Len(p$)
bak=1
Repeat
  x=FindString(var$+p$,p$,bak+1)
  If x
    c+1
    If c=indice
      ProcedureReturn Mid(var$,bak,x-(bak))
    EndIf
    bak=x+lp
  EndIf        
Until x=0
EndProcedure


;thanks dom

Posted: Wed Dec 22, 2004 2:49 pm
by Karbon
It is early and I haven't had my coffee yet but I don't see any benefit over the built in StringField() function?

STRINGFIELD BETTER

Posted: Thu Dec 23, 2004 12:00 am
by dom
Karbon wrote:It is early and I haven't had my coffee yet but I don't see any benefit over the built in StringField() function?
HI Karbon

TRY IS CODE, change idea.

thanks dom....
sorry my english...

Code: Select all

Procedure.s stringfield2(var$,indice,p$)
lp=Len(p$)
bak=1
Repeat
  x=FindString(var$+p$,p$,bak+1)
  If x
    c+1
    If c=indice
      ProcedureReturn Mid(var$,bak,x-(bak))
    EndIf
    bak=x+lp
  EndIf        
Until x=0
EndProcedure


a$="123456789stop123456789stoppurebasicstopisstopcool"

;using STRINGFIELD NORMAL
Debug StringField(a$,1,"stop")
Debug StringField(a$,2,"stop")
Debug StringField(a$,3,"stop")
Debug StringField(a$,4,"stop")
Debug StringField(a$,5,"stop")
Debug StringField(a$,6,"stop")
Debug StringField(a$,7,"stop")
Debug StringField(a$,8,"stop")
Debug StringField(a$,9,"stop")


;using STRINGFIELD2 MODIFIED
Debug StringField2(a$,1,"stop")
Debug StringField2(a$,2,"stop")
Debug StringField2(a$,3,"stop")
Debug StringField2(a$,4,"stop")
Debug StringField2(a$,5,"stop")
Debug StringField2(a$,6,"stop")
Debug StringField2(a$,7,"stop")
Debug StringField2(a$,8,"stop")
Debug StringField2(a$,9,"stop")

Posted: Thu Dec 23, 2004 2:57 pm
by ebs
dom,

What you've found is that PureBasic's StringField() function can only accept a delimiter of ONE character. Your function removes this restriction, and is handy with delimiters like "stop".

Regards,
Eric