FindString optional start parameter

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

FindString optional start parameter

Post by kenmo »

A very small suggestion here: Now that the length parameter of Mid() is optional and defaults to 1, doesn't it make sense that the start position parameter of FindString() should as well? No functionality change at all, just a little less clutter.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

I support this suggestion/wish. This is possible with Instr() in all other Basic flavours that I know. Having this option in PB would make converting code like this

Code: Select all

i = Instr(Main$, Part$)
from other Basic flavours easier.

Regards, Little John
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

With Mid() the parameter became optional because it reduced a lot of typing
and the need for yet another string command (Len). For example...

Code: Select all

Mid(windowsfolder$,10,Len(windowsfolder$))
...became so much simpler and quicker to type:

Code: Select all

Mid(windowsfolder$,10)
But with FindString(), all you need to type are 2 little chars at the end: ,1
And Macros can always give you a new version of the command that makes
porting from other Basics easier:

Code: Select all

Macro InStr(main,part) : FindString(main,part,1) : EndMacro
Debug InStr("12345","3") ; Returns 3.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

Yes ... And probably Fred or Freak will need about 10 minutes or so to make the suggested change. :-)

Regards, Little John
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Well, they have said in the past that it requires a recompile of the required
lib and doc changes in three languages... and they are not keen to do that
just because someone doesn't want to type: ,1
Plus it breaks all existing apps that use FindString.
Still think they'll do it? I'd be very surprised.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

PB wrote:Plus it breaks all existing apps that use FindString.
No, not at all! It will not break a single line of code, since

Code: Select all

FindString(Main$, Part$, 1)
would still be legal code, of course. The suggestion is that the coder would be allowed to omit the start position, not that s/he would be forced to do so. The latter wouldn't make sense anyway.

It is paradox that we can use optional parameters in self-written procedures, but not in a built-in function such as FindString().

Regards, Little John
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Sorry, I forgot it would be optional. :oops:
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

PB wrote:With Mid() the parameter became optional because it reduced a lot of typing
and the need for yet another string command (Len). For example...

Code: Select all

Mid(windowsfolder$,10,Len(windowsfolder$))
...became so much simpler and quicker to type:

Code: Select all

Mid(windowsfolder$,10)
Oh, you're right! I thought if you left out that parameter it would read 1 character, not until the end of the string. Good to know.

But I still like the optional FindString() idea. :)
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

I second this as I am frequently forgetting to add the ,1 to the end of FindString() and I almost NEVER need to use anything other than ,1 .

Also, I would like the final length parameter to default to 1 for Left() and Right().
Anthony Jordan
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

+1 here as well, the third parameter does always force me to do another compile... so actually, the pb devs would need 10 minutes, yet they would save humanity hours and days and weeks and months and perhaps years!

:)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

akj wrote:Also, I would like the final length parameter to default to 1 for Left() and Right().
Ah yes, +1 for that as well!
Post Reply