LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search string in a file

Hi,

 

I am reading a serial port and writing the data to a .txt file. I want to read this file and scan it for a certain string, i then want to write this string and a couple of extra characters to a seperate file. I can do this for one occurance of the string, but the string occurs a few times each time, but not always the same number of times. Is it possible to search for several occurances of the same string.  for example my serial read looks like this:

 

abcdef Speed 12

abcdef

abcdef Speed 99

abcdef

abcdef

abcdef Speed 10

 

I need to find all the speeds so i search the file for 'Speed' and write this plus the two numbers to an output file. however it only finds the first 'Speed 12' and not the others. the number of times 'Speed' appears varies from test to test.

 

Thank you 

0 Kudos
Message 1 of 7
(12,752 Views)

Hi Dowden1,

you can use the match pattern function a loop. Connect the "offset past match" output to a shiftregister and use it as input to the match pattern function. Initialize the shiftregister with 0 and stop the loop if the "offset past match" is smaller than 0.

 

Mike

Message 2 of 7
(12,746 Views)

Hi Mike,

 

Thanks for your help, this works as far as scanning the file and getting multiple mathces however it does not seem to stop very well any ideas?

 

Thank you

 

Adam

0 Kudos
Message 3 of 7
(12,724 Views)

What do you mean by " it does not seem to stop very well" ?

 

Please post your code.

0 Kudos
Message 4 of 7
(12,709 Views)
this VI will find speed and spit out the "speed" text and numeric "xx" value. Many way to do this...
Message 5 of 7
(12,707 Views)

Hi,

 

This is an other way to do this.

 

In the first time, I search if the text have the string ""abcdef Speed " + number"and I split the string. After I take the value and I put it in the array.

 

When it haven't anymore "Speed" it's produce an error that stop the while, so i need to delete the last entry of the array to have only good value and not 0 à the end.

 

You must clear error after, if you want to use it.

 

 

Message 6 of 7
(12,694 Views)
In Ajangot code you need to put a shift register on the "Match Pattern" func... else you keep reading the same file and not the parsed file on the next scan. He's aready mention about clearing the error and removing the last index in the array.
Message 7 of 7
(12,673 Views)