07-06-2011 08:42 AM
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.
Solved! Go to Solution.
07-06-2011 08:53 AM - edited 07-06-2011 08:53 AM
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
07-06-2011 08:56 AM
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) .
07-06-2011 09:05 AM - edited 07-06-2011 09:08 AM
@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
07-06-2011 09:09 AM - edited 07-06-2011 09:09 AM
@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 😞
07-06-2011 09:10 AM
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.
It really comes down to what you are trying to achieve.
07-06-2011 09:10 AM
@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.
07-06-2011 09:25 AM
Thank you guys!
The second method in Count_char_occurrences.png works realy good.
Best regards.
07-06-2011 11:42 AM
For the heck of it, my pre-S&R method of counting chars or strings was this:
07-07-2011 12:37 AM
Darin.K that's good! Allows to count not only chars but substrings.