StringField better

Share your advanced PureBasic knowledge/code with the community.
dom
New User
New User
Posts: 3
Joined: Tue Dec 21, 2004 5:26 pm
Location: Brazil - Parana

StringField better

Post 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
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
dom
New User
New User
Posts: 3
Joined: Tue Dec 21, 2004 5:26 pm
Location: Brazil - Parana

STRINGFIELD BETTER

Post 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")
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
Post Reply