11-12-2009 09:02 AM
Hello NI Developers!
I have a problem. At first I thought that this will be very easy, but It's not, maybe only for me.
I have a text file and there are many articles inside. Those articles are split to each other by several empty lines.
There are 3-5 lines between articles, but there are also empty lines in each article but not more then 2 empty lines.
I need a VI that could read all text from file, then count empty lines and if it finds 3-5 empty lines - split each article into
separate file.
For example if there is text inside file like this:
----------------------------------------
TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1
TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1
_ (1 empty line)
TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1
TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1
TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1 TEXT-1
_
_
_ Empty lines (3 - 5)
_
TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2
_ (1 empty line)
TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2
TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2 TEXT-2
_
_
_
TEXT-3 TEXT-3 TEXT-3 TEXT-3 TEXT-3 TEXT-3
TEXT-3 TEXT-3 TEXT-3 TEXT-3 TEXT-3 TEXT-3
......
......
I need to place this TEXT1, TEXT2, TEXT3 into individual files.
I tried for loop, while loop, but no success... Simply not working, it writes all text into one file.
Any help much appreciated,
Thanks in advance
11-12-2009 09:28 AM
You basically have three fundamental flaws with your program:
Off the top of my head, I can think of two basic ways of solving the problem:
11-12-2009 05:00 PM
1) I tried making this code and spent about 12 hours.
2) Believe me, I tried different file names, but only in this example I removed part of code, because it makes me mad already.
3) Your suggested comparison with [LR/CR] to fetch an empty line is not working
4) What do you suggest using instead of function "Insert into Array" ?
11-12-2009 05:05 PM
This is not working. Why ??
11-12-2009 05:55 PM
Sorry, my mistake. The EOL will get chopped off. Everything else I said was correct, though. Note that you could have easily determined this by putting a probe on the string wire.
See if the attached works for you. I didn't test it all that much, so you may need to correct it. Note that it's in 8.2. For 8.5 or higher you can make the for-loop a conditional stop on error so you don't keep spinning if you get a file I/O error.
11-12-2009 06:37 PM
Thank you smercurio_fc for help.
Comaprison to CR/LF works just perfect. It was my mistake as I did it not correct.
I've just finished my implementation and saw your reply. See my attached VI, it's not so pretty like your, but it is working. Anyway I guess I should learn some tips/tricks from your coding style. I like code where is used Ternary operator (Select node), it looks great, but I tried doing myself this way and couldn't get code to work and was confused.
Thank you!
11-12-2009 06:46 PM
smercurio_fc wrote: " For 8.5 or higher you can make the for-loop a conditional stop on error so you don't keep spinning if you get a file I/O error. "
Actually I think it can be done in any version of LabView, isn't it ?
Simply unbundle True/False data from Error cluster and wire it to Case structure.
11-12-2009 07:01 PM
11-12-2009
11:14 PM
- last edited on
05-09-2025
07:59 PM
by
Content Cleaner
ACiDuser wrote:
smercurio_fc wrote: " For 8.5 or higher you can make the for-loop a conditional stop on error so you don't keep spinning if you get a file I/O error. "
Actually I think it can be done in any version of LabView, isn't it ?
Simply unbundle True/False data from Error cluster and wire it to Case structure.
No, I'm talking about the for-loop in LabVIEW 8.5 or higher having a conditional terminal just like a while loop.