LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the number of lines in a string?

I have a lone string with multiples lines (return). How can I find out how many lines in the string?
0 Kudos
Message 1 of 7
(5,351 Views)
You could use the "SpreadString to Array" function to convert the string to an array and then look at the size of the array. Hope this helps..
0 Kudos
Message 2 of 7
(5,351 Views)
In article <506500000005000000B6C60000-1042324653000@exchange.ni.com>,
"VipersView" wrote:

> You could use the "SpreadString to Array" function to convert the string
> to an array and then look at the size of the array. Hope this helps..

I run into this problem a lot. I agree with VipersView. The other way is
to use a while loop that searches for the carriage return or line feed at
the end of each line and simply count how many times it finds it. Use the
'Match Pattern' function and search until the 'offset past match' is equal
to -1.

VipersView's method is obviously simpler. You may want to compare speed
differences when using very large files.

- Kevin
0 Kudos
Message 3 of 7
(5,351 Views)
Thanks for your answer. By the way how to enter the carriage return or line feed? This may work for my case. I have a file with some lines of description and then numeric data, and this repeat several times. I want to develop a vi to automatically find out the data and read them and skip the description. I need to read each line and check if it is alpabetic or numeric and then make decision.

Thanks for your help.

Jianmin
0 Kudos
Message 4 of 7
(5,351 Views)
For a little more information on the original question, you might also check here, or search the NI site for the "wc" command.
0 Kudos
Message 5 of 7
(5,351 Views)
For the counting of no.of lines, try the Line Counter here http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000BB700000&USEARCHCONTEXT_CATEGORY_0=_49_%24_6_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

As for extracting data without having worry over the description, you may wanna try using "Configuration File VI" in LabVIEW's File I/O function palletes.

Regards
ian.f
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 6 of 7
(5,351 Views)
For how to extract data from a (Configuration/ .ini)file. Please do consider Create the file using Configuration File VIs, which will then allow you to extract data easily.

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000002D6F0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

Also, Jean-Pierre Drolet has got something just what you are looking for.

Regards
ian.f
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 7 of 7
(5,351 Views)