Summary: In this exercise, the objective is to use the Build String, Match Pattern, Scan from String, and String Length functions. Complete the following steps to build a VI that converts a numeric value to a string, concatenates the string to other strings to form a single output string, and determines the output string length. The VI also matches a pattern in a string and converts the remaining string to a numeric value.
![]() Figure 1 |
String 2 and select
'\' Codes Display from the
shortcut menu.
The text typed in String 2 is
Volts DC: +1.26E+1. As shown using
Codes display in the front panel above, there are
two spaces after the colon (\s\s), and
the text ends with a carriage return
(\r\n). You may see only a
\r or a \n for the
carriage return.
String Length and Offset
Past Match to 32-bit signed integer (I32)
representation.
Operate>>Make Current Values Default to
set the text as the default values of these
controls.
![]() Figure 2 |
Build Text Express
VI, located on the
Functions>>Output palette, on the block
diagram. This function converts Number
to a string. The Build Text configuration dialog box
appears.
%Header% %Number% %Trailer% in
the Text with Variables in Percents
text box to create three variables. The
variables appear in the Configure
Variables section.
Number in the
Variable section.
Variable Properties section,
select the Number option, set the
Format to Format fractional
number. Place a checkmark in the
Use specified precision checkbox
and set the Precision to
4. Leave the Header
and Trailer variables in the
default state.
OK button to close the
dialog box.
String
Length function, located on the
Functions>>All Functions>>String
palette, on the block diagram. This function returns
the number of characters in Result.
Match
Pattern function, located on the
Functions>>All Functions>>String
palette, on the block diagram. This function
searches String 2 for a colon
(:).
Right-click the regular expression
input, select Create>>Constant from the
shortcut menu, type a colon (:), and
press the <Enter> key on the numeric
keypad. You also can click the Enter
button on the toolbar to complete the entry. Do not
use the <Enter> key on the main
keyboard because in this case it adds the return
character to the search expression.
Scan From
String function, located on the
Functions>>All Functions>>String
palette, on the block diagram. This function
converts the string after the colon to a numeric
value.
![]() Figure 3 |
Create String.vi in the
C:\Exercises\LabVIEW Basics I
directory. You will use this VI later in the course.
Header,
Number, and Trailer into
Combined String and displays the string
length.
The VI also searches String 2 for a colon,
converts the string following the colon to Number
Out, and displays the index of the first
character after the colon in Offset Past
Match.
Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."