Use the String functions located on the
Functions>>All Functions>>String
palette to edit and manipulate strings on the block diagram. String functions include the following:- String Length: Returns in length the number of characters (bytes) string, including space characters. For example, the
String Length
function returns a length of19
for the following string:The quick brown fox
- Concatenate Strings: Concatenates input strings and 1D arrays of strings into a single output string. For array inputs, this function concatenates each element of the array. Add inputs to the function by right-clicking an input and selecting
Add Input
from the shortcut menu or by resizing the function. For example, concatenate the previous string with the following array of strings:TheTABLE 1 jumped
over
the
lazy
dog.
Concatenate Strings
function returns the following string:The quick brown fox jumped over the lazy dog.
- String Subset: Returns the substring of the input string beginning at offset and containing length number of characters. The offset of the first character in string is
0
. For example, if you use the previous string as the input, theString Subset
function returns the following substring for an offset of4
and a length of5
:quick
- Match Pattern: Searches for regular expression in string beginning at offset, and if it finds a match, splits string into three substrings. If no match is found, match substring is empty and offset past match is -1. For example, use a regular expression of
:
and use the following string as the input:TheVOLTS DC: +1.22863E+1;
Match Pattern
function returns a before substring ofVOLTS DC
, a match substring of:
, an after substring of+1.22863E+1;
, and an offset past match of9
.
Converting Numeric Values to Strings with the Build Text Express VI
Use the
Build Text
Express VI to convert numeric values into strings. The Build Text
Express VI, located on the Functions>>Output
palette, concatenates an input string. If the input is not a string, this Express VI converts the input into a string based on the configuration of the Express VI.When you place the
Build Text
Express VI on the block diagram, the Configure Build Text dialog box appears. The dialog box shows the Express VI configured to accept one input,voltage
, and change it to a fractional number with a precision of 4. The input concatenates on the end of the string Voltage is
. A space has been added to the end of the Voltage is
string.This configuration produces the block diagram shown in Figure 2. A probe has been added to view the value of the output string. The
Build Text
Express VI concatenates theBeginning Text
input, in this case the voltage
value, at the end of the configured text.Converting Strings to Numeric Values with the Scan From String Function
The
Scan From String
function converts a string containing valid numeric characters, such as 0-9
, +
, -
, e
, E
, and period (.
), to a numeric value. This function scans the input stringand converts the string according to format string. Use this function when you know the exact format of the input text. This function can scan input string into various data types, such as numeric or Boolean, based on the format string. Resize the function to increase the number of outputs.EXAMPLE 1
For example, use a format string of
%f
, an initial search location of 8
, and VOLTS DC+1.28E+2
as the input string, to produce an output of 128
, as shown in the block diagram shown in Figure 3. Change the precision of the output by changing the precision of the indicator.In format string,
%
begins the format specifier and f
indicates a floating-point numeric with fractional format. Right-click the function and select Edit Scan String
from the shortcut menu to create or edit a format string. The Edit Scan String dialog box shows a configuration for the format string %4f
.Refer to the LabVIEW Help for more information about format specifier syntax.
No comments:
Post a Comment