To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example is a simple VI that performs a word count on a string by counting spaces between words.
Description
This VI uses the match pattern VI to search a string and count the number of spaces, effectively doing a wordcount.
Requirements
Steps to Implement or Execute Code
Additional Information or References
VI Block Diagram
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Your vi doesn't account for a text string that may contain multiple space between words or words separated by tabs or other punctuation.
A better match pattern string would be "[A-Za-z-]+" which will count actual strings of characters as words including hyphenated words.
you could also then remove the +2 as the loop will run a final iteration where it doesn't find a word which will offset the 0 based iteration count.
Hi, Steve
I'm beginner in labview and I did not understand what is "[A- Za- z -] +" can you explain bettter witch string I have to use for my counter disregard more than one space between words please
thanks,
Carol Vieira
Carol, The match pattern vi treats that as a search string for any combination of the uppercase A-Z and the lowercase a-z and the hyphen character joined together. ie, a word.
The + after the brackets means it will match any number of those successive characters until it hits a character that's not part of that set.
It's not looking for spaces so any number of spaces would not count as a match and therefore be ignored. MHutch's example above counts spaces not words, but if you define a word as a string of alpha characters and perhaps hyphenated then the "[A-Za-z-]+" would search for "words". Perhaps an apostrophe character as well could added to the string within the brackets, but I doubt it would affect the word count.
Thank you very much
Hi Steve03,
Can you please explain more about how to use special characters in match pattern functions.
Appreciate if you can provide more & more examples for each special characters.
Thanks.
Thank you Steve.
This really help.