LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search text file and return relevant data?

Hi All,

 

I have a text file which is formatted as follows:

 

[Part Number]

123123

 

[Batch Number]

456456

 

[Work Order Number]

789789

 

and so on... Always with a [parameter] followed by some data.

 

How would I search the file and return just the data for a single parameter ? For example, If i wanted to search the file and return just the Batch Number (456456), is this possible ? I can't seem to get any of the built in string functions to work for me?

 

Thanks in advance for your help,

 

 

 

0 Kudos
Message 1 of 4
(660 Views)

Well, first you would read the entire file, then operate on the resulting string. Then you would use a while loop to search for the parameter(+linefeed) and then read read the following line until all are found.

 

It is hard to tell what you are doing wrong unless you show us what you are doing. Note that you probably need to escape some characters (e.g. [,], etc.) that have special meaning in expressions. 

0 Kudos
Message 2 of 4
(655 Views)

You can also read the file as an array of lines, simplifying the rest of the code a little bit. Here are two possible approaches:

 

altenbach_0-1643820824752.png

 

(note that you can directly read the file as an array of lines using read from text file)

 

0 Kudos
Message 3 of 4
(641 Views)

Here's how you could use match pattern (note the "\" to change the meaning)

 

 

altenbach_0-1643821413260.png

 

Might need a few tweaks, depending how EOL is defined (LF, CRLF, etc.). There are dozens of different ways to do all that, of course. Try to find a few more! 😄

 

0 Kudos
Message 4 of 4
(636 Views)