It is currently Tue Nov 19, 2019 1:17 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 10:24 am 
Offline
User
User

Joined: Sun Aug 27, 2017 7:37 pm
Posts: 29
Location: Slovenia
I would like to suggest to support negative numbers with Left.

Manual says:

Code:
Result \$ = Left ( String$ , Length )


It would be nice to have an option to just specify a negative number which would tell how many characters are removed from the source string.

For example:

Code:
result$=Left ("abcdef", -1)


would return

Code:
abcde


(one character from the right removed).

This would probably mean shorter .exe because

Code:
result$=Left ("abcdef", Len ("abcdef") - 1)


is much longer (which at the end produces longer .exe files).

Same could apply for Right.

Maybe some other functions could use the same system.

Just think about it and maybe implement it.

In the mean time maybe documentation could be updated to include the range of the Length. For example:

"Length: value specified must be an integer higher than zero." (of course rephrase this)

Saso


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 12:57 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 264
Location: France
I agree. That could be cool.

_________________
~Ar-S~

ResizerGold : The easiest way to resize your pictures and more
My webSite (french) : LDVMULTIMEDIA
PB - 5.4x LTS / 5.6x - W10 x64 - GTX1080 - i5 6600k
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 1:20 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 6:41 am
Posts: 794
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 1:28 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1106
Location: Germany::Berlin()
+1

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 1:41 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2043
Location: Germany
+1

Update. Only macros
Code:
;-TOP
;-TOP

Macro PB(Function)
  Function
EndMacro

Macro Left(String, Lenght)
  PB(Left)(String, Lenght + (Bool(Lenght<0)*Len(String)))
EndMacro

Macro Right(String, Lenght)
  PB(Right)(String, Lenght + (Bool(Lenght<0)*Len(String)))
EndMacro

; --------

r1.s ="12345678"

Debug Left(r1, 2)
Debug Left(r1, -2)
Debug Right(r1, 2)
Debug Right(r1, -2)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Fri Feb 22, 2019 2:06 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 565
+ 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Tue Jun 11, 2019 9:47 pm 
Offline
User
User

Joined: Thu May 02, 2019 3:57 am
Posts: 41
Location: USA
This is a great idea which has already been implemented in other compilers. I hope it gets implemented in PB.


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Wed Jun 12, 2019 1:37 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3591
Location: Utah, USA
@mk-soft: I'm always glad to see code suggestions on how to obtain a solution through various means. Just a comment on your macro offering, they are useful as syntatic sugar but they will result in longer execution whether or not a negative number is used for length because the Len() will be calculated on every execution of the macro whether or not it is needed.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Left () and Right () with negative numbers
PostPosted: Wed Jun 12, 2019 6:52 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3703
Location: Berlin, Germany
Code:
Macro Left_negative (_string_, _lenght_)
   Left(_string_, Len(_string_) + (_lenght_))
EndMacro

Macro Right_negative (_string_, _lenght_)
   Mid(_string_, -(_lenght_) + 1)
EndMacro


; -- Demo
text$ = "12345678"

Debug Left_negative (text$, -2)
Debug Right_negative(text$, -2)

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye