Showing results for 
Search instead for 
Did you mean: 

Best way to search a text file for a keyword?

Go to solution

So I would like to implement an ability of my VI to open a text file and then using some kind of search function, locate and highlight a keyword that the user enters. Pretty much like when you hit Ctrl F in your internet browser and other places. 


I've tried List Folder Function, but that only says whether a file you name is in a certain location. And I've tried Match Pattern but that only splices the file into before and after segments of where the keyword is. 


Is there a better function to do this?

0 Kudos
Message 1 of 3

Hi Orta,


so you know how to open and load a (text) file. And you already know a function you can use to search for keywords.

What else do you need?

Best regards,

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 3
Accepted by ShogunOrta

You can use a while loop and a shift register to go through the text using the Match pattern function. If you find a match, you can go to next iteration and use a new offset value. You also need to check when you finished searching the string. This should be a simple task to program. Try to do it, and if you find problems to solve this, upload your VI here (not a screenshot!) so people can help you...


edit: something like this can help:



0 Kudos
Message 3 of 3