LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

count the number of occurences in a text file

hi all,
 
iam new to Labview, i would like to know
how can we count the number of occurences of a character
in a text file(till the end of file). This text file contains of data(numbers, symbols and characters)
in multiple lines,plz help.
 
Regards,
santosh.
 
 
Regards,
santosh
0 Kudos
Message 1 of 8
(5,676 Views)
Hi Santosh,

when counting single chars I would do following:

Message Edited by GerdW on 09-14-2006 09:56 AM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(5,671 Views)

Very good example Gerd,

One way to overcome the overflow problem is to implement the solution (shown below) within a loop.  You read the file line by line and keep adding the number of occurrences of each line to the total.  In a document, a single character, such as a space or letter "a" will occur very often. 

I think "Read lines from file.vi" could be useful or you can implement something similar to suit your needs.  Another method is to read the text in blocks and index each block at a time for every iteration of the loop.  Make sure you keep track of the end of the file.

RayR

0 Kudos
Message 3 of 8
(5,659 Views)

hello gerd,

thanks for ur good reply,

and Joe i request you to provide the example that u r talking about,

i think u missed attaching the file,

regards,

santosh.

Regards,
santosh
0 Kudos
Message 4 of 8
(5,647 Views)

Sorry santosh,

I should have revisited this thread.  I'll try to post an example over the wekend.

RayR

0 Kudos
Message 5 of 8
(5,596 Views)

Another option would be to read the file and input the string into the Spreadsheet String to Array function (using your character as the delimiter) and then use the Array Size function on that array.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).

Message Edited by tst on 09-30-2006 11:35 PM


___________________
Try to take over the world!
Message 6 of 8
(5,572 Views)

Hey Gerd,

What is the function you were using in that VI?

If you still have the VI itself that's even better..

Yours,

mm035b

0 Kudos
Message 7 of 8
(4,955 Views)

@mm035b wrote:

Hey Gerd,

What is the function you were using in that VI?

If you still have the VI itself that's even better..

Yours,

mm035b


Which function are you referring to?

  1. String to Byte Array
  2. Index Array
  3. Equal
  4. Bollean to (0,1)
  5. Sum Array Elements

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(4,942 Views)