Crop commands to cut strings short

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Crop commands to cut strings short

Post by PB »

I often have to crop the last char off a string, using this:

Code: Select all

a$=Left(a$,Len(a$)-1)
I know it's not much to type, but it is when used in conjunction with
other commands (LCase, etc). It'd be great to have something like
a$=RCrop(a$,1) (where "1" = number of chars to crop).

You could even go further and have both LCrop(string$,chars) so
we could stop having to do this:

Code: Select all

a$=Mid(a$,startpos,chars)
:)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Is there a strandard name in other language for this ? Sounds a nice idea.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Is there a strandard name in other language for this ?

I don't think so, I haven't even seen them in other languages.
But I think LCrop (for removing the first X chars) and RCrop
are nice names for them -- after all, we're cropping the strings.

BTW, the reason I'd like LCrop is for the reason given at this
post: viewtopic.php?t=8193
Last edited by PB on Wed Nov 05, 2003 10:04 am, edited 1 time in total.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

maybe "Cut" or "Trim" are better words?

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> maybe "Cut" or "Trim" are better words?

Trim exists for removing spaces at the moment. I guess parameters
could be added but it would break existing code in a big way.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Yeah, I was thinking of LTrim and Rtrim.. but I just noticed these allready exist.. :lol:

Maybe Cut would be ok then.. or Slice even?!?

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Maybe Cut would be ok then.. or Slice even?!?

Hehehe, I like crop because crop means to cut something short.

From http://dictionary.reference.com/search?q=crop :

To cut (hair, for example) very short.
To clip (an animal's ears, for example).
To trim (a photograph or picture, for example).
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

LarsG wrote:maybe "Cut" or "Trim" are better words?
'Trim' is for removing leading/trailing spaces

RCut or LCut are named perfect for this

A.s="Rings"

debug RCut(A.s,1)
prints "Ring"


easy command to implement, just do it like this:

;Rcut is easy
Procedure RCut(instringpointer.l,Pos)
PokeB(Instringpointer+lstrlen_(Instringpointer)-Pos,0)
EndProcedure

A.s="Siggi Rings"
RCut(@A.s,1)
Debug A.s


A.s="Siggi Rings"
LCut_Position=5
;LCut only with asm
!MOV eax,dword[v_LCut_Position]
!add dword[v_A],eax
Debug A.s

another topic is the StringBasepointer, i don't know if it must be realigned after this....but thats you turn Fred ;)
SPAMINATOR NR.1
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Yeah, il like this command also
Lcut an Rcut sounds okay for me
crop sounds like vegetables in the garden ;)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Fred wrote:Is there a strandard name in other language for this ? Sounds a nice idea.
BTW: FindString() is called in other languages instr() ...
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> BTW: FindString() is called in other languages instr() ...

Yes, but instr is a very bad name for that. Back in my QB days, i could
never remember that name. FindString() is much better to remember,
and also describes the purpose of the function better.

Timo
quidquid Latine dictum sit altum videtur
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

>Yes, but instr is a very bad name for that.

Maybe, but you search IN a STRing :)

And maybe it is a good idea to put the Macros on top of the todo-list (and of course, macros should be added in the res), so a simple

MACRO InSTR(Parent$,Find$,Position)=FindString(Parent$,Find$,Position)

make PB more standard (and maybe easier for newcomers from other Basic-Languages).
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I fear this abuse with the implementation of Macro. If everyone build its compatibility layer, it will be impossible to share it to the community. Anyway, anyone can do as they want.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I fear this abuse with the implementation of Macro.
Me too :? i can see code getting muddled and harder to understand!
--Kale

Image
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

Kale wrote:
I fear this abuse with the implementation of Macro.
Me too :? i can see code getting muddled and harder to understand!
nop, totaly disagree

code become more handy reading.

and of course all macros must been include at the top or via Includefile.pbi
SPAMINATOR NR.1
Post Reply