{"id":185,"date":"2007-07-02T10:20:46","date_gmt":"2007-07-02T10:20:46","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/2007\/07\/02\/reading-through-text-files-in-memory\/"},"modified":"2007-07-02T10:20:46","modified_gmt":"2007-07-02T10:20:46","slug":"reading-through-text-files-in-memory","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2007\/07\/02\/reading-through-text-files-in-memory\/","title":{"rendered":"Reading through text files in memory"},"content":{"rendered":"<p>Looping through a text file is commonly achieved with the ReadLn command in a loop, like the example in the help file:<\/p>\n<blockquote>\n<pre>Let>k=1\nLabel>start\nReadLn>c:\\\\\\temp\\\\\\test.txt,k,line\nIf>line=##EOF##,finish\nMessageModal>line\nLet>k=k+1\nGoto>start\nLabel>finish<\/pre>\n<\/blockquote>\n<p>This uses a very simple loop and loops through the file one line at a time using the ReadLn command and a counter variable.<\/p>\n<p>An alternative method is to read the entire file into memory and then put the lines into an array.  This means seeking through the file becomes faster, and it becomes easier to change individual lines.   Use the ReadFile command to read the entire file content into a variable:<\/p>\n<blockquote>\n<pre>ReadFile>c:\\\\\\temp\\\\\\test.txt,TheFileData<\/pre>\n<\/blockquote>\n<p>We now have a variable called TheFileData containing all the lines in the file.  Each line will be separated by a Carriage Return, Line Feed combination (CRLF).  So we can now split the file into an array using the Separate command, specifying CRLF as the delimiter:<\/p>\n<blockquote>\n<pre>Separate>TheFileData,CRLF,Lines<\/pre>\n<\/blockquote>\n<p>Lines_Count now tells us how many lines there are and we can access each line with Lines_1, Lines_2, etc.  So here&#8217;s the new version of the full script:<\/p>\n<blockquote>\n<pre>ReadFile>c:\\\\\\temp\\\\\\test.txt,TheFileData\nSeparate>TheFileData,CRLF,Lines\nLet>k=1\nRepeat>k\n  Let>CurrentLine=Lines_%k%\n  MessageModal>CurrentLine\n  Let>k=k+1\nUntil>k>Lines_Count<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Looping through a text file is commonly achieved with the ReadLn command in a loop, like the example in the help file: Let>k=1 Label>start ReadLn>c:\\\\\\temp\\\\\\test.txt,k,line If>line=##EOF##,finish MessageModal>line Let>k=k+1 Goto>start Label>finish This uses a very simple loop and loops through the file one line at a time using the ReadLn command and a counter variable. An [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/185"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=185"}],"version-history":[{"count":0,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/185\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}