Page 1 of 1
UnLeft() and UnRight() Command
Posted: Thu Apr 20, 2006 11:21 pm
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

Posted: Thu Apr 20, 2006 11:30 pm
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"
Posted: Thu Apr 20, 2006 11:53 pm
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
Posted: Fri Apr 21, 2006 12:15 am
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.
Re: UnLeft() and UnRight() Command
Posted: Fri Apr 21, 2006 12:41 am
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
Posted: Fri Apr 21, 2006 10:20 am
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...
Re: UnLeft() and UnRight() Command
Posted: Fri Apr 21, 2006 10:41 am
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"