Using LabVIEW Scan From String to Parse Numbers and More

Updated Aug 21, 2023

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full

Issue Details

I am using the Scan From String function (Functions»String palette) in LabVIEW. With this function I can easily parse out numbers and basic strings. However, I want to be able to use this function in a more advanced way. How can I use the format string input to scan in a specific character set, a character set separated by a specific character, or a character set of a specific length?
 

Solution

Sometimes, you want to be able to use more advanced features when using the Scan From String function. Here are some examples of different format strings that will allow you to scan in a specific character set, a character set separated by a specific character, or a character set of a specific length. See Format Specifier Syntax for more examples:

Scanning in character sets 
The format for scanning in a specific character set is %character set.  The character set must be listed in ascending ASCII order.  For example, %[ A-Za-z] (note the space before the "A") returns any string with any alphabetical characters and spaces. Note that the ASCII value of a space is 32, and the value of a capital A is 65. Therefore, [A-Za-z ] (note the space after the "z" this time) will not include a space in the character set because the set is not in ascending ASCII. You can add a comma or other character to the set, as long as this character is included in the correct numerical ASCII order. 
 
Scanning in strings delimited by a specific character 
To read strings separated by commas you would use the format string %[A-Za-z],. The format string %s, will not work, as it will just read in the entire string with the first %s.

Scanning in strings of a specific length 
To read a string of a certain length, you would use the format string %10s or %10[A-Za-z], where 10 is the length.

Refer to the LabVIEW Help, available by selecting Help»VI, Function, How-To Help in LabVIEW, for more information about scanning strings.