Removing text problem

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
IXIS

Removing text problem

Post by IXIS » Mon Oct 11, 2004 5:17 pm

Hello All,

I have a question here. I have a certain bit of text in an ini file that needs to be slightly reformated, but i'm having troubles with it. The problem comes from the fact that the text needed to be removed is at the end of a string that changes length. If the string was always the same length, I could just use MidStr to get only what I want, but thats not the case. An example would be...

WLS-AM_20040828_19_00.mp3.pat
WABC-AM_20040830_06_00.mp3.pat

...would be the string in question. What I need to do is remove the ".mp3.pat" from the end of the string. Until now, I have actually been opening the ini file up in notepad and removing them that way, but I would like this function to be transparent in the background. Like I said before, the MidStr command is not an option becuase of the string being different lengths at different times.

Any Ideas?

thanks,
Terry
:lol:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Oct 11, 2004 6:02 pm

So use the Position function to see if the .mp3.pat exists in the string and if so where abouts:


Let>string=WABC-AM_20040830_06_00.mp3.pat
Position>.mp3.pat,string,1,pos
if>pos=0,forgetit
Let>pos=pos-1
MidStr>string,1,pos,res
MessageModal>res
Label>forgetit


Use ReadIniFile and WriteIniFile to retrieve the value and write it back. Example above just uses a set value. It will work with any length strings.
MJT Net Support
[email protected]

Lumumba

Post by Lumumba » Mon Oct 11, 2004 7:00 pm

Had another approach (TBH quite similar).

Let>Line = WABC-AM_20040830_06_00.mp3.pat

Length>%Line%, LineLn
Sub>%LineLn%, 8
MidStr>%Line%, 1, %LineLn%, Line
MessageModal>%Line%

IXIS
Newbie
Posts: 3
Joined: Mon Oct 11, 2004 5:20 pm
Contact:

Post by IXIS » Mon Oct 11, 2004 7:00 pm

Thanks so much!

You just made things a lot easier for me now :lol:

regards,
Terry

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1415
Joined: Sun Nov 03, 2002 3:19 am

Post by Dorian (MJT support) » Tue Oct 12, 2004 4:26 pm

support wrote:Position>.mp3.pat,string,1,pos
Aaah, fantastic! I haven't seen this command used before. To remove the ".XXX" from a filename I always got the LEN of the filename, took away 4, then renamed it using midstr.

I also have a daily macro which reads every line of a 200MB web log file, so >position is really going to help me.

Thanks guys.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts