02-01-2007 03:52 AM
02-01-2007 04:27 AM
02-01-2007 08:09 PM - edited 02-01-2007 08:09 PM
Message Edited by q123456789 on 02-01-2007 08:15 PM
02-01-2007 10:26 PM
Instead of using 'Read From Text File' put the 'Read From Spreadsheet File' on your block diagram. Now, open it's block diagram. In there you will find the old 'Read Lines From File' vi. Drag it into your block diagram and delete the 'Read from Spreadsheet File' vi. This is, IMHO, much more useful for reading text files as one of its outputs the position in the file where you stop reading (we will use this later). I do not know why NI chose to take this output out of 'Read From Text File', I think they made a big mistake.
Now, you want to read the second and third words in the second line. Here's how: (Follow along in the attached image)
Wire the path to your file to 'Read Lines From File' and a constant 1 to 'number of rows'. Leave other inputs at default.
Drop another instance of 'Read Lines From File' to the right of the first one.
Wire the 'new file path' output of the first to 'file path' input of the second. Again wire a constant 1 to 'number of lines' to the second.
Wire 'mark after read' output of the first to 'start of read offset' of the second. You now have the second line of the file.
Wire it to 'Match Pattern' with a constant space wired to 'regular expression'. The 'after substring' will be the line from the second word on.
Wire this into 'Match Pattern', again with a space. The 'before substring' output is the second word and the 'after substring' is the line from the third word on.
Wire this into 'Match Pattern', again with a space. The 'before substring' output is the third word.
It's a little 'brute force', but it will work. With a little extra work with loops and shift registers you could pull out any word in any line.
02-02-2007 03:30 AM