[Implemented] Unlimited Separator$ length @ StringField()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

[Implemented] Unlimited Separator$ length @ StringField()

Post by AND51 »

Hello!

My favourite command StringField() can only work correctly, if Separator$ has only 1 character.

Can this be extended? It'd be nice, if Separator$ can have any length! :D

Concerning this topic, you might have a look at the german forum-thread: http://www.purebasic.fr/german/viewtopi ... D51#127649
PB 4.30

Code: Select all

onErrorGoto(?Fred)
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

Or a debugger check to help people avoid this problem. One could also
change the type of the separator to CHARACTER.

But I agree, it would be VERY useful to allow any length of string as
Separator$.
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Agreed!

I want this really bad! :!:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

But it would me much slower.
Apart from that Mrs Lincoln, how was the show?
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

Post by Dummy »

Konne wrote:But it would me much slower.
only if it's badly coded or you use seperator "ae" on a verly long string filled with 50% "a"s
Last edited by Dummy on Wed Dec 06, 2006 10:36 pm, edited 1 time in total.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Konne wrote:But it would me much slower.
That's not the matter.

If the PB Team has no other idea, the PB team will use one big If/Else, checking if Separator$'s length is =1 or >1. So, the perfomance doesn not decrease.



@ PB Team: What do you think about my idea? As you can see, there are many other ppl who aagree with me. :D
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Fluid Byte wrote:Agreed!

I want this really bad! :!:
I want it good, if you don't mind? :wink:
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

I agree this would be useful.. here's hoping for it to appear in the future.. also agree 2 versions of the function should be provided (or internally detected) if the >1 char version is known to be slower than the 1 char version.
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Agreed too!

Greetings ... Kiffi
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

So we're all agreed then. It's a must-have feature for PureBasic 13.0
Anthony Jordan
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Not PB 13.0 :P but next PB version or PB update.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Post by JCV »

yup its a nice addition. :D
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

Didn't we talk about this and Fred said that it is a stupid idea?.
I don't know.
Apart from that Mrs Lincoln, how was the show?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Unlimited Separator$ length @ StringField()

Post by PB »

I'd just do it like this, with a non-standard text character such as Chr(1) as a placeholder.
So, use StringField for 1 character delimiters, and StringFieldBig for >1 character delimiters.

Code: Select all

Procedure.s StringFieldBig(string$,index,delimiter$)
  string$=ReplaceString(string$,delimiter$,Chr(1))
  ProcedureReturn StringField(string$,index,Chr(1))
EndProcedure

For k=1 To 6
  Debug StringFieldBig("Hello---I---am---a---split---string", k, "---")
Next
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Smaller, faster, better. Morever, you forgot to protect the variable, that's bad (think of EnableExplicit).

Code: Select all

Macro StringFieldBig(string,index,delimiter) 
   StringField(ReplaceString(string,delimiter,Chr(1)) ,index,Chr(1)) 
EndMacro

For k=1 To 6 
  Debug StringFieldBig("Hello---I---am---a---split---string", k, "---") 
Next 
I know, how to code a better Stringfield; but this iis not the point. I would like too see an improved StringField in the next Version natively!
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply