• No results found

String Functions

In document LabView Tutorial (Page 164-168)

Hex Display Displays the ASCII value of each character in hex instead of the

Use the table control located on the ControlsAll ControlsList & Table palette or the Express Table VI located on the ControlsText Indicators palette to create a table on the front panel. Each cell in a table is a string, and each cell resides in a column and a row. Therefore, a table is a display for a 2D array of strings. The illustration in Figure 9.1 shows a table and all its parts.

Figure 9.1: 1. Cell Indicated by Index Values, 2. Column Headings, 3. Vertical Scrollbar, 4. Horizontal Scrollbar, 5. Row Headings, 6. Horizontal Index, 7. Vertical Index

Dene cells in the table by using the Operating tool or the Labeling tool to select a cell and typing text in the selected cell.

The table displays a 2D array of strings, so you must convert 2D numeric arrays to 2D string arrays before you can display them in a table indicator. The row and column headers are not automatically displayed as in a spreadsheet. You must create 1D string arrays for the row and column headers.

9.2 String Functions

2

Use the String functions located on the FunctionsAll FunctionsString 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 char-acters. For example, the String Length function returns a length of 19 for the following string:

The quick brown fox

2This content is available online at <http://cnx.org/content/m12253/1.2/>.

157 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:

jumped over the lazy dog.

Table 9.2

The 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 oset and containing length number of characters. The oset of the rst character in string is 0. For example, if you use the previous string as the input, the String Subset function returns the following substring for an oset of 4 and a length of 5:

quick

Match Pattern - Searches for regular expression in string beginning at oset, and if it nds a match, splits string into three substrings. If no match is found, match substring is empty and oset past match is −1. For example, use a regular expression of : and use the following string as the input:

VOLTS DC: +1.22863E+1;

The Match Pattern function returns a before substring of VOLTS DC, a match substring of :, an after substring of +1.22863E+1;, and an oset past match of 9.

9.2.1 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 FunctionsOutput palette, concatenates an input string. If the input is not a string, this Express VI converts the input into a string based on the conguration of the Express VI.

When you place the Build Text Express VI on the block diagram, the Congure Build Text (Figure 9.2) dialog box appears. The dialog box (Figure 9.2) shows the Express VI congured 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.

Figure 9.2

This conguration produces the block diagram shown in Figure 9.3. A probe has been added to view the value of the output string. The Build Text Express VI concatenates the Beginning Text input, in this case the voltage value, at the end of the congured text.

159

Figure 9.3

9.2.2 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 string and 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 9.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 9.4. Change the precision of the output by changing the precision of the indicator.

Figure 9.4

In format string, % begins the format specier and f indicates a oating-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 (Figure 9.5) dialog box shows a conguration for the format string %4f.

Figure 9.5

Refer to the LabVIEW Help for more information about format specier syntax.

In document LabView Tutorial (Page 164-168)