Mid(MyString$, Offset, Characters)
Mid(MyString$, Offset, Characters)
Some other BASICs I have used allow you to select all characters to the right of a position in a string using the syntax:
RParts$ = mid(MyString$, Offset)
PB always requires the three paramaters nomally associated with Mid(), so I need to write:
RPart$ = Mid(MyString$, N, Len(MyString$)-N+1) ; Messy
or:
RParts$ = Mid(MyString$, N, BigNumber) ; Works but not 'clean'
where I am sure that BigNumber is longer than the balance of the string.
Please could PB support the two parameter version of the call?
RParts$ = mid(MyString$, Offset)
PB always requires the three paramaters nomally associated with Mid(), so I need to write:
RPart$ = Mid(MyString$, N, Len(MyString$)-N+1) ; Messy
or:
RParts$ = Mid(MyString$, N, BigNumber) ; Works but not 'clean'
where I am sure that BigNumber is longer than the balance of the string.
Please could PB support the two parameter version of the call?
-
- Addict
- Posts: 841
- Joined: Mon Jun 07, 2004 7:10 pm
How does Left() or Right() help here?
Left() starts at the beginning of the string and Right() starts from the end.
Mid() is the only one that allows for a starting position within the string.
I agree it would be nice to have the string length in Mid() as an option.
If no length is specified then length to end of string is used.
Often I use:
Mid(String$,pos,Len(String$))
Since PB seems to stop when the end of the string is reached, and this guarantees your length will exceed what is remaining in your string.
Left() starts at the beginning of the string and Right() starts from the end.
Mid() is the only one that allows for a starting position within the string.
I agree it would be nice to have the string length in Mid() as an option.
If no length is specified then length to end of string is used.
Often I use:
Mid(String$,pos,Len(String$))
Since PB seems to stop when the end of the string is reached, and this guarantees your length will exceed what is remaining in your string.

Yes, of course!
(I have been programming with various BASICS for about 25 years.)
If I need all of a string to the right of a particular position, and the string does not have a fixed length Right() does not help.
Mid(String$, Start, Length) gves me what I want, but I have to calculate the value of Length.
PB stores strings with NULL terminators so the additional logic in MID() to (a) Detect no third parameter and set a flag then (2) Maka string of everything from 'Start' to the NULL into the returned value probably takes about as much work as writing this note!

(I have been programming with various BASICS for about 25 years.)
If I need all of a string to the right of a particular position, and the string does not have a fixed length Right() does not help.
Mid(String$, Start, Length) gves me what I want, but I have to calculate the value of Length.
PB stores strings with NULL terminators so the additional logic in MID() to (a) Detect no third parameter and set a flag then (2) Maka string of everything from 'Start' to the NULL into the returned value probably takes about as much work as writing this note!
I'm using this:
Code: Select all
Macro Mids(A,n)
Mid(A,n,Len(A))
EndMacro
b$="abcdefgh"
Debug Mids(b$,2)
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
Paul wrote:How does Left() or Right() help here?
Code: Select all
Macro MidInf(String, StartPos)
Right(String, Len(String)+1-StartPos)
EndMacro
Trond:
Your macro is clever but slower.
Your macro is clever but slower.
Code: Select all
Macro MidInf(String, StartPos)
Right(String, Len(String)+1-StartPos)
EndMacro
Macro Mids(A,n)
Mid(A,n,Len(A))
EndMacro
b$="abcdefgh"
ti=GetTickCount_()
For i=0 To 100000
A$= Mids(b$,2)
Next
Debug GetTickCount_()-ti
ti=GetTickCount_()
For i=0 To 100000
A$= MidInf(b$,2)
Next
Debug GetTickCount_()-ti
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Faster:

Code: Select all
Macro Mids(A,n)
PeekS(@A+n-1)
EndMacro

NEVER EVER NEVER EVER NEVER EVER enable the debugger when you're doing speed tests. Turn off the debugger and mine is faster.
But I didn't realize this was a speed competition. This beats everything so far:
But I didn't realize this was a speed competition. This beats everything so far:
Code: Select all
Macro MidInf2(String, StartingPos)
PeekS(@String + SizeOf(Character)*(StartingPos-1))
EndMacro
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
even faster (macro is redundant)
Peeks(@string$+ n)
Peeks(@string$+ n)
Last edited by netmaestro on Thu May 04, 2006 8:05 pm, edited 1 time in total.
BERESHEIT
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Trond wrote:NEVER EVER NEVER EVER NEVER EVER enable the debugger when you're doing speed tests. Turn off the debugger and mine is faster.
But I didn't realize this was a speed competition. This beats everything so far:Code: Select all
Macro MidInf2(String, StartingPos) PeekS(@String + SizeOf(Character)*(StartingPos-1)) EndMacro

But far from the same functionalitynetmaestro wrote:even faster (macro is redundant)
Peeks(@string$, n)

EVEN faster:
Code: Select all
Z + 1 - 3