Delete part of text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Delete part of text

Post by AlessioForconi » Sun Nov 18, 2018 4:27 pm

Klaus wrote:
Sun Nov 18, 2018 10:37 am
OK, OK, let me put it this way, I think this is also what the dictionary means.
In a repeat for each loop like this:

Code: Select all

...
repeat for each line temp in tFiles
         ## do whatever you want to with temp:
         delete char -4 to -1 of  temp
         ## if temp was -> my_image.jpg 
         ## then it now is in fact -> my_image
end repeat
...
You can modify temp and do with it whatever you like, but the "container" (tFiles in this case) will NOT change in the end, means tFiles BEFORE the loop = tFiles AFTER the loop.

It is always difficult to explain something like this in your non-native language.
Thank you Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Delete part of text

Post by dunbarx » Sun Nov 18, 2018 5:28 pm

@Klaus.

Oh, that is what you meant. Well, sure. :wink:

@ Jacque.

I thought so. But you can indeed (at least these days) fool around with the index midstream. I will test HC tomorrow. I have a feeling my little handler will not like it there.

Craig

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: Delete part of text

Post by hpsh » Mon Nov 19, 2018 4:51 am

just wonder a bit about this, deleting chars -1 to -4 in a filename, where the end could be something like mytext.lz would make it to mytex.
would it not be better to set itemdel to "." transfer item 1 to a new string, and then replace the original with the new string?
would also fix a problem on Unix like system where the filename could be something like mytext.tar.gz

maybe just me that is tired, or something I don't get, would not be the first time

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Delete part of text

Post by AlessioForconi » Mon Nov 19, 2018 7:44 am

hpsh wrote:
Mon Nov 19, 2018 4:51 am
just wonder a bit about this, deleting chars -1 to -4 in a filename, where the end could be something like mytext.lz would make it to mytex.
would it not be better to set itemdel to "." transfer item 1 to a new string, and then replace the original with the new string?
would also fix a problem on Unix like system where the filename could be something like mytext.tar.gz

maybe just me that is tired, or something I don't get, would not be the first time
You are right. The fact is that in this case I know exactly what I want to eliminate. It is always and only the last four letters of the file, the point and the extension, so it is a code that must do only that and only in this case with those files.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Delete part of text

Post by dunbarx » Mon Nov 19, 2018 3:33 pm

@hpsh

Your thinking is correct; it is much more robust.

I have often chosen "the easy" way in a handler, thinking surely I did not need to deal with anything unexpected. Just as often, I had to go back and rework. Those unexpected things keep popping up.

Craig

Post Reply