UnLeft() and UnRight() Command

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Booster698
New User
New User
Posts: 7
Joined: Wed Apr 19, 2006 10:30 pm
Location: France

UnLeft() and UnRight() Command

Post by Booster698 »

It could be usefull to have these commands for strings manipulations :

Example:

Code: Select all

Result.s = UnLeft("GoodBye" , 3)  ; Result will be "Good"
Result.s = UnRight("GoodBye" , 4) ; Result will be "Bye"
It can produce a better method than :

Code: Select all

Result.s = Left(Result, Len(Result) - 3)
Would be nice :)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

you can do it easily with macro

Code: Select all

Macro UnLeft(string,length)
  Left(string, Len(string) - length)
EndMacro
Macro UnRight(string,length)
  Right(string, Len(string) - length)
EndMacro

Debug UnLeft("GoodBye" , 3)  ; Result will be "Good"
Debug UnRight("GoodBye" , 4) ; Result will be "Bye"
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Booster698
New User
New User
Posts: 7
Joined: Wed Apr 19, 2006 10:30 pm
Location: France

Post by Booster698 »

Thanx i've already coded my own but i just give an idea to improve purebasic :)

Code: Select all

Procedure.s UnLeft(String.s, Length)
  ProcedureReturn Left(String, Len(String) - Length)
EndProcedure

Procedure.s UnRight(String.s, Length)
  ProcedureReturn Right(String, Len(String) - Length)
EndProcedure
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

Are those commands that are common in other Basic dialects? I'd hate to see the language become cluttered with functionality that can be easily accomplished with existing, well-known and understood commands.

I'm all for constructively evolving the language but respectfully put me down for NO on this one.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: UnLeft() and UnRight() Command

Post by blueznl »

Booster698 wrote: Result.s = UnLeft("GoodBye" , 3) ; Result will be "Good"
Result.s = UnRight("GoodBye" , 4) ; Result will be "Bye"

Result.s = Left(Result, Len(Result) - 3)
don't see much use... doesn't this do the same?

result.s = left("GoodBye",4)
result.s = mid("GoodBye",5,1000)

but if you really want it, i admit i use a small sub sometimes :-)

Code: Select all

Procedure.s x_chop(string.s,left.l,right.l)                          ; chop a bit of the left and right side of a string
  ; *** chop 'n' characters from the left or right of a string
  ;
  l = Len(string)
  If right > 0
    string = Left(string,l-right)
  EndIf
  If left > 0
    string = Mid(string,left+1,l)
  EndIf
  ;
  ProcedureReturn string
  ;
EndProcedure
( 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... )
maw

Post by maw »

To be honest, if I really could make a wish I would wish for a return to SuperBASIC on the Sinclair QL. In a sence, PB already has alot in common with it, but there is one thing I really miss and that is it's string manipulation. It had neither Left, Right nor Mid. Instead...

Code: Select all

a$ = "ABCDEFG"
b$ = a$(1 To 4) ; would return ABCD
b$ = a$(To 4) ; would return ABCD
b$ = a$(-4 to -7) ; would return ABCD
b$ = a$(-1 To -3) ; would return EFG
b$ = a$(-3 To 7) ; would return EFG
b$ = a$(5 To) ; would return EFG
b$ = a$ ; would return the whole string
This brings back memories.. How I miss that computer! Almost as much as my Amiga...
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Re: UnLeft() and UnRight() Command

Post by freedimension »

Booster698 wrote:It could be usefull to have these commands for strings manipulations :

Example:

Code: Select all

Result.s = UnLeft("GoodBye" , 3)  ; Result will be "Good"
Result.s = UnRight("GoodBye" , 4) ; Result will be "Bye"
I would rather like to see the existing commands enhanced:

Code: Select all

Result.s = Left("GoodBye" , -3)  ; Result will be "Good"
Result.s = Right("GoodBye" , -4) ; Result will be "Bye"
<°)))o><²³
Post Reply