Add Each line to An Array

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
mholmes3038
Newbie
Posts: 3
Joined: Sun Dec 06, 2015 5:59 pm

Add Each line to An Array

Post by mholmes3038 » Sun Dec 06, 2015 6:08 pm

I'm new to this tool so please pardon my "newb" question or questions. When I first started working on this task I thought it might be best to simply open up the document in notepad and use windows keyboard commands to do this but the task requested I do it differently. Anyway, I searched the forums and I was able to get this far in my task. The request is to copy the data in this file and then parse each line. What I'm trying to do right now is loop through each line and add it to an array. I found a snippet but I'm not able to get it to work and I honestly don't even understand it.

Here is my current code:

Code: Select all

//Variables
let>FilePath=C:\Users\Micah\Downloads\Work Stuff\Macro Job\Report.txt
**BREAKPOINT**



/*Open Document
press>ctrl
press>esc
release>ctrl
release>esc
send>filename
Wait>1
press>tab
release>tab
press>enter
release>enter
*/

//Read Document
ReadFile>FilePath,Report

//Add Lines to Array
GetClipboard>report
Let>tmp0=(?m)(?<=^Line \d: ).+?$
RegEx>tmp0,report,0,M,NM,0
The section I'm trying to figure out right now is this:

Code: Select all

//Add Lines to Array
GetClipboard>report
Let>tmp0=(?m)(?<=^Line \d: ).+?$
RegEx>tmp0,report,0,M,NM,0
Just need a tut or sample on how to read a line in a text file and add it to an array. I was not able to find any thing in the documentation about this and the samples on here seem a bit crude or at least hard to follow. Does anyone have simple samples of reading a line in a text document and adding that line to an array, or video tuts those are very helpful as well. Thanks.

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

Re: Add Each line to An Array

Post by Marcus Tettmar » Mon Dec 07, 2015 3:43 pm

To read a file into an array where each line is an array entry is as simple as this:

Code: Select all

ReadFile>path_to_file,fileContent
Separate>fileContent,CRLF,myArray
That's it! Separate splits a string into an array based on a delimiter. In your file, lines are delimited by a carriage return + line feed pair. So that's all you need.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mholmes3038
Newbie
Posts: 3
Joined: Sun Dec 06, 2015 5:59 pm

Re: Add Each line to An Array

Post by mholmes3038 » Tue Dec 08, 2015 12:16 am

Thanks for the reply I think I get it now. Read line will read the line and then CRLF tells it to go to the next line. So I just place this in a loop and it will add each line to my array. Great!!!

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