Make startposition optional in FindString()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Demivec
Addict
Addict
Posts: 4258
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Make startposition optional in FindString()

Post by Demivec »

I know this is a low priority request but a sensible one nonetheless.

FindString() is currently defined like this:

Code: Select all

Position = FindString(String$, StringToFind$, StartPosition)
Please change it to:

Code: Select all

Position = FindString(String$, StringToFind$ [, StartPosition]) ;StartPosition = 1 if not specified
It seems to me that FindString() is called with StartPosition = 1 at least half the time and this would simplify things a bit.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Make startposition optional in FindString()

Post by blueznl »

+1
( 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... )
Little John
Addict
Addict
Posts: 4775
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Make startposition optional in FindString()

Post by Little John »

+1

In the old BASIC flavours that I know, startposition of Instr() has always been optional.
As long as it's not implemented in PB, I use this:

Code: Select all

Macro Instr (_source_, _search_, _p_=1)
   FindString(_source_, _search_, _p_)
EndMacro
Regards, Little John
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Make startposition optional in FindString()

Post by skywalk »

Yes please.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Suirad
User
User
Posts: 42
Joined: Sun Sep 20, 2009 7:37 pm
Location: Melbourne, Florida, USA

Re: Make startposition optional in FindString()

Post by Suirad »

how hard is it to add ", 1" to the end of a command?
why dont you just wrap it in another procedure if its that much of a hastle?

Code: Select all

Procedure fFindstring(string.s,stringtofind.s,startposition=1)
  ProcedureReturn FindString(string,stringtofind,startposition)
EndProcedure
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Make startposition optional in FindString()

Post by KJ67 »

Suirad wrote:why dont you just wrap it in another procedure
Doing a wrapper with a procedure will give you extra overhead, Little John’s version with a macro is more efficient.
The best preparation for tomorrow is doing your best today.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Make startposition optional in FindString()

Post by blueznl »

Oh, it's a minor request, but it's true: most applications will use ,1 so why enforce millions of hits on thousands of keyboards, sore muscles and countless of kilojoules in energy wasted, all that energy used by the CPU to recompile because yet someone yet again has forgotten the ,1 and on top of it there's the electricity used to light up the room where the poor programmer is slaving his day away and neglecting his family for hour after hour (cumulative speaking, of course) because of the ,1 ?

You... you... you... energy waster!
( 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... )
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Make startposition optional in FindString()

Post by Fred »

:lol:
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Make startposition optional in FindString()

Post by Kukulkan »

+1
User avatar
shadow
User
User
Posts: 34
Joined: Thu Dec 16, 2010 1:25 pm
Location: Germany

Re: Make startposition optional in FindString()

Post by shadow »

+1
ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Make startposition optional in FindString()

Post by Tenaja »

Suirad wrote:how hard is it to add ", 1" to the end of a command?
why dont you just wrap it in another procedure if its that much of a hastle?
If you require the 1, then you break all existing code. That's a lot of work. Maybe not all for PB, but for all of its users.

BTW, count me as a +1 for this, too.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: Make startposition optional in FindString()

Post by AND51 »

—1


Why all the +1's ... ? I thought you want to omit the ,1 so actually you all should write -1 in this thread, shouldn't you? :P :lol:

(SCNR)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Make startposition optional in FindString()

Post by PB »

Most apps don't use ,1 at all. Mine certainly don't! It depends on the app. The suggestion to drop it will break my sources just because you don't use it. Why is your code more important than mine? Use a simple macro and be done with it.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
kenmo
Addict
Addict
Posts: 2032
Joined: Tue Dec 23, 2003 3:54 am

Re: Make startposition optional in FindString()

Post by kenmo »

+1

This wouldn't break any current code! It would simply remove a lot of ",1"s from future code.
Little John
Addict
Addict
Posts: 4775
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Make startposition optional in FindString()

Post by Little John »

PB wrote:Most apps don't use ,1 at all. Mine certainly don't! It depends on the app. The suggestion to drop it will break my sources just because you don't use it. Why is your code more important than mine? Use a simple macro and be done with it.
No!
Making StartPosition optional in FindString() will not break any existing code.
Post Reply