Stop Extra Line when using WriteLn

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Stop Extra Line when using WriteLn

Post by Dominic_Fichera » Tue Feb 24, 2015 11:01 am

Hey guys,

I am currently trying to write a script that reads a file (any filetype) and spits out the first line, deletes the existing file and recreates a file with all the information but the used line (in lieu of a "delete line" action - Please excuse any small errors as I've just typed this up quickly).

Currently, I have a script that reads every line 1 by 1 and transfers them to a new file, but this takes a considerable amount of time. I am just trying to streamline the process.

Code: Select all

//This is where I read the original file
ReadFile>C:\Users\Dom\Desktop\test.txt,varOriginalFile

//This is where I count how many lines there are
Separate>varOriginalFile,%CRLF%,totalLines

//This is where I get the line of data from the file
Let>varData=totalLines_%totalLines_Count%

//This is where I remove the used data line from the variable
StringReplace>varOriginalFile,varData,,varNewFile

//This is where I delete the old file and create the new file
DeleteFile>C:\Users\Dom\Desktop\test.txt
WriteLn>C:\Users\Dom\Desktop\test.txt,nWLNRes,varNewFile

MessageModal>This is the remaining lines of Data: %totalLines_Count%%CRLF%%CRLF%This is the line of data: %varData%
When it writes the new file, it always adds an extra blank line where it removes the data line. Is there anyway to remove the line break completely? If I can't remove the line break completely, it messes up the counting and all subsequent actions. (This is obviously to do with the WriteLn function, not the rest of the script, but I wanted to give some background).

Hope this makes sense :)

Thanks in advance,

Dominic Fichera

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Stop Extra Line when using WriteLn

Post by Marcus Tettmar » Tue Feb 24, 2015 2:40 pm

To stop WriteLn adding a line feed, set WR_NOCRLF to 1 first:

Let>WLN_NOCRLF=1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Stop Extra Line when using WriteLn

Post by Dominic_Fichera » Thu Feb 26, 2015 12:10 pm

Hi Marcus,

Thanks for your reply! :)

I gave that a go before I posted here and there still seems to be the problem.

I have made a screen recording to try and explain my situation, because I don't think I am explaining it very well :)

https://www.dropbox.com/s/jo9vczv9c8a67 ... k.mp4?dl=0

Thanks again

Dominic Fichera

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Stop Extra Line when using WriteLn

Post by Marcus Tettmar » Thu Feb 26, 2015 1:49 pm

You start with something like this

11111111111<line break>
22222222222<line break>
33333333333<line break>
44444444444<line break>

You replace 44444444444 with nothing ("") so you get:

11111111111<line break>
22222222222<line break>
33333333333<line break>
<line break>

So you really want to replace "44444444444<line break>" with nothing.

Or, simply Trim the whole thing before you write it back:

Trim>varNewFile,varNewFile
WriteLn>c:\...\test.txt,nwlnRes,varNewFile
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Stop Extra Line when using WriteLn

Post by Dominic_Fichera » Fri Feb 27, 2015 6:32 am

Hi Marcus,

Trim did the trick! Thanks so much! :)

Dominic Fichera

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