11-04-2008 04:58 AM
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
11-04-2008 05:14 AM
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
11-04-2008 07:08 AM
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
11-04-2008 08:58 AM
What do you mean by " it does not seem to stop very well" ?
Please post your code.
11-04-2008 09:00 AM
11-04-2008 09:37 AM
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.
Aurélien J.
National Instruments France
11-04-2008 01:09 PM