Example Code

Counting the Number of Matches in a String in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview
This VI shows two approaches to count a specific character within a string.

 

Description

This VI shows two different ways to count how many times a character occurs within a string. In a first way, LabVIEW converts the string to a byte array and then indexes through each byte using a For Loop. LabVIEW compares each byte to the *. In a second way, LabVIEW uses a While Loop to iteratively parse through the incoming string. The example uses * as the character to search for.

 

Requirements
LabVIEW Base Development System (or compatible)

 

Steps to Implement or Execute Code
1. Run the VI
2. Change the string by adding more characters with *
3. See the change


Additional Information or References

Snippet.png


**This document has been updated to meet the current required format for the NI Code Exchange.**

Aashish M
CEO
TransferFi
www.transferfi.com

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
GregFreeman
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

delete

GregFreeman
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

What about something like this:

nummatches.png

JonP
Member
Member
on

Search and Replace String tells you and (I'm guessing) is probably no slower especially if you set the replacement string to be the same length as the search string:

FindReplace.jpg