LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of lines in a file

Hello,

is there an existing component to determine the number of lines in a .txt
file for example?

TIA,

Bull's
0 Kudos
Message 1 of 5
(2,901 Views)
Unfortunately no. You will have to build one yourself. The basic way to approach things is to pass the contents of the file into a while loop containing a match pattern primative. Have a shift register on the loop that carries the location of the last sting found and loop until the search string isn't found anymore. When the loop terminates the number of iterations will be equal to the number of lines.

The one tricky part is defining the search string. If you know what the EOL delmiter is for the program generating the file is--use it. Otherwise try the string [\r\n]+ (with slash codes enabled). This string will match any number of consecutive carriage returns or line feeds. The only problem with this generic solution is that it won't catch empty lines...


If you can't get something going give me a hollar and I'll put something together for you...

Mike

mporter@arielcorp.com

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(2,901 Views)
Thx for the help
While waiting for an answer, I figured out how to do it myself, andd
surprisingly just the way you said

Greetz

Bull's

"mikeporter" schreef in bericht
news:506500000005000000285E0000-1012609683000@exchange.ni.com...
> Unfortunately no. You will have to build one yourself. The basic way
> to approach things is to pass the contents of the file into a while
> loop containing a match pattern primative. Have a shift register on
> the loop that carries the location of the last sting found and loop
> until the search string isn't found anymore. When the loop terminates
> the number of iterations will be equal to the number of lines.
>
> The one tricky part is defining the search string. If you know what
> the EOL delmiter is
for the program generating the file is--use it.
> Otherwise try the string [\r\n]+ (with slash codes enabled). This
> string will match any number of consecutive carriage returns or line
> feeds. The only problem with this generic solution is that it won't
> catch empty lines...
>
> If you can't get something going give me a hollar and I'll put
> something together for you...
>
> Mike
>
> mporter@arielcorp.com
0 Kudos
Message 4 of 5
(2,901 Views)
Steven,
Under Functions> File I/O menu is a "Read Lines From File.vi".
Wire your file path refnum into it, It will output a line string.
Wire that into a "Spreadsheet String to Array.vi" with a "Carriage Return" constant wired into the delimiter input.
Wire its output array into an "Array size.vi" and you should have your number of lines.

Good Luck with it, Doug
Message 3 of 5
(2,901 Views)
Thx, this one is much shorter than the one I wrote myself...


"Doug (CapeFl)" schreef in bericht
news:5065000000050000002D5E0000-1012609683000@exchange.ni.com...
> Steven,
> Under Functions> File I/O menu is a "Read Lines From File.vi".
> Wire your file path refnum into it, It will output a line string.
> Wire that into a "Spreadsheet String to Array.vi" with a "Carriage
> Return" constant wired into the delimiter input.
> Wire its output array into an "Array size.vi" and you should have your
> number of lines.
>
> Good Luck with it, Doug
>
0 Kudos
Message 5 of 5
(2,901 Views)