LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

char occurrences

Solved!
Go to solution

Hi All!

How can i find all char occurrences in a string.

For instance in the string -  "This is a string" the char "i" appears three times.

I use Labview 7.1.

Regards.

0 Kudos
Message 1 of 10
(4,400 Views)
Solution
Accepted by topic author john7

Hi john,

the attached image shows 2 methods how you can do it with LabVIEW 7.1. The first can be used if you only count a char, the second can be used to count strings.

 

Hope it helps.

Mike

0 Kudos
Message 2 of 10
(4,392 Views)

Even easier is to use "Search and Replace String" with 'replace all?' set to True. This will tell you how many replacements it did (and thus how many matches there are) .

Message 3 of 10
(4,384 Views)

@dan_u wrote:

Even easier is to use "Search and Replace String" with 'replace all?' set to True. This will tell you how many replacements it did (and thus how many matches there are) .



As far as i know this function (the output of the replacements) was not yet implemented in LabVIEW 7.1.

 

Mike

0 Kudos
Message 4 of 10
(4,376 Views)

@MikeS81 wrote:

@dan_u wrote:

Even easier is to use "Search and Replace String" with 'replace all?' set to True. This will tell you how many replacements it did (and thus how many matches there are) .



As far as i know this function (the output of the replacements) was not yet implemented in LabVIEW 7.1.

 

Mike


Hmm, it was available (http://zone.ni.com/reference/en-XX/help/lv/71/glang/Search_and_Replace_String/) but it did not return the number of replacements.
Too bad 😞

0 Kudos
Message 5 of 10
(4,366 Views)

Here is another method. It will depend on your ultimate goal as to what you need to do and what work best for you. I can think of 5 more ways to do the same thing that have not been suggested.

 

Example.png

 

It really comes down to what you are trying to achieve.

Tim
GHSP
0 Kudos
Message 6 of 10
(4,363 Views)

@dan_u wrote:

Even easier is to use "Search and Replace String" with 'replace all?' set to True. This will tell you how many replacements it did (and thus how many matches there are) .



@Mike wrote:

As far as i know this function (the output of the replacements) was not yet implemented in LabVIEW 7.1.



Mike is correct. While the function existed in LabVIEW 7.1, it did not have the "number of replacements" output.

0 Kudos
Message 7 of 10
(4,362 Views)

Thank you guys!

The second method in Count_char_occurrences.png works realy good.

Best regards.

0 Kudos
Message 8 of 10
(4,346 Views)

For the heck of it, my pre-S&R method of counting chars or strings was this:

 

CountChars2.png

0 Kudos
Message 9 of 10
(4,331 Views)

Darin.K that's good! Allows to count not only chars but substrings.

0 Kudos
Message 10 of 10
(4,312 Views)