07-16-2014 08:36 AM
Hello I want to read a text file that could look in some different ways since the user choose file from a list. I then want to igonre all the lines that begin with a special character, for example %. I then want to find all the lines "words" that begin with TRY for example and put those "words" in a string or array. If there is one line that contains TRY100 and anoter line that contains TRY200 I want to find those words and display them. How do i do this?
07-16-2014 08:38 AM
@qweewq11 wrote:
Hello I want to read a text file that could look in some different ways since the user choose file from a list. I then want to igonre all the lines that begin with a special character, for example %. I then want to find all the lines "words" that begin with TRY for example and put those "words" in a string or array. If there is one line that contains TRY100 and anoter line that contains TRY200 I want to find those words and display them. How do i do this?
Instead of expecting someone to provide you with a VI, you need to demonstrate that you have attempted to do this.
Post your VI.
07-16-2014 08:44 AM
But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.
07-16-2014 08:46 AM
First you read the entire file. Use the Read Text File. Right-click on it and select the option to Read Lines. The the count to read to -1 (read all). You will now have an array of strings, one item for each line of your file.
Now you need to play the filter game. I recommend using FOR loops with Autoindexing tunnels. Assuming you are using 2012 or later, have the output autoindexing tunnels use the conditional tunnel.
Give this a try and see where you can go. Post back with what you have tried and tell us where you are stuck.
07-16-2014 08:49 AM
@qweewq11 wrote:
But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.
HOLD it your are posting on the NI discussion forums LabVIEW board and you "cannot open a vi?"
However, you can learn more here by mistake than most places.
Have you ever heard of a Regex or, "Regular expression?" Just click the blue text... It will take you someplace nice..
07-16-2014 09:01 AM
@qweewq11 wrote:
But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.
You can't find any good solution?
How about looking at the Examples that ship with LabVIEW?
Or reading a tutorial or two?
07-17-2014 05:02 AM
Hi qweewq11,
Saying that you don't want a VI is quite confusing here. Are you looking for a LabVIEW solution or a non-LabVIEW solution ?
If you want to go with LabVIEW, just follow the recommandations of crossrulz and you should go in the right direction.
If you are looking for a non-LabVIEW solution, there are languages more suited for text processing, like Perl. But then you are not on the right forum 😉
In any case, the keyword here will be the regular expression, just as Jeff suggested above ! For LabVIEW, be sure to check the "Match Regular Expression" function.
Kind regards,
07-17-2014 07:57 AM
Thanks I solved it buy using Match Pattern i a for loop and then put all my words in an array. In the array i removed all the blank elemets that are in between. My problem now is if a line starts with for example % i want to remove that line. So if i have an 1d array with the lines %abc, bcd, %cde and def i want to remove the lines with %abc and %cde and keep bcd and def. Any idea of how i coluld make that possible. I have tried to find a solution for hours.
07-17-2014 08:04 AM
What version of LabVIEW are you using? If using 2012 or newer, you can use Conditional tunnels on a FOR loop. So you autoindex your array of strings into the FOR loop. Use String Subset to just look at the first character and check that it is not a "%". So you will autodindex out of your FOR loop the original string, except that you have the conditional on it. Use the output of the Not Equal as your condition.
07-17-2014 08:26 AM
No i use older versions than 2012 unfortunately...