Jump to content
Macro Express Forums

Parsing Data from a Pipe-Delimited Text File


Recommended Posts

Hello Forum,

 

I just recently discovered this excellent tool and have a rather complex requirement that I'm hoping it can handle.

 

I need to loop through all lines of a pipe-delimited text file. The goal is to parse out each of the 6 data fields per line, insert each of those 6 data fields into an interface, go to the next line, and repeat.

 

The pipe-delimited text file includes a Header and would look like this:

 

PersonID|FirstName|LastName|Age|Gender|Active

P0100|John|Smith|20|M|Y

P0200|Ashley|Williams|21|F|Y

P0300|Robert|Adams|37|M|Y

 

I started playing around with the "Text File Begin/End Process" command but wasn't able to get very far. I should be able to handle the steps for navigating to the interface field and inserting the data, but I'm stuck on how to read the file and assign each field to a variable that can be inserted.

 

I greatly appreciate your help!

 

Thanks

Link to comment
Share on other sites

I can think of a few ways to do this. Here is a simple one:

Text File Begin Process: c:\test.txt // Process each line, one at a time
 Split String "%ALine%" on "|" into %Fields%, starting at 1 // Split the line into elements of an array

 // Here the content of the fields are in %Fields[1]%, %Fields[2]%, %Fields[3]%, ... %Fields[6]%

Text File End Process

Copy and paste this into a macro to try it.

<TEXT FILE BEGIN PROCESS Filename="c:\\test.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%ALine%" _COMMENT="Process each line, one at a time"/>
<SPLIT STRING Source="%ALine%" SplitChar="|" Dest="%Fields%" Index="1" _COMMENT="Split the line into elements of an array"/>
<COMMENT/>
<COMMENT Value="Here the content of the fields are in %Fields[1]%, %Fields[2]%, %Fields[3]%, ... %Fields[6]%"/>
<COMMENT/>
<TEXT FILE END PROCESS/>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...