Assign – Strings Review

advertisement
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
Name:
Based on your experience working with 1D and 2D numerical arrays, you should be able
to carry out the activities listed below and answer the associated questions.
Understanding how to work with strings in LabVIEW is a very important concept. Your
answers to these questions can serve as great study notes for the tests that will follow!
Answer the following questions in the space provided. Feel free to add additional space,
as needed. If the addition of screenshots would help to answer/explain, then include
screenshots. Submit a copy of this file to your teacher when you have completed the
assignment.
Front Panel & Block Diagram
This assignment focuses on working with text strings using function blocks in LabVIEW. All of
the string-related blocks referenced in this assignment are in the Strings palette or in one of
three subpalettes (Additional String Functions, String/Number Conversion, or Conversion)
located on the Strings palette. Don’t make this assignment just about answering
questions. Spend enough time playing around with each block to understand how it functions.
For blocks that have inputs for index and/or offset values, pay attention to how invalid input
values are handled (i.e. index values outside the range for the given input array). Also, pay
attention to what blocks can be expanded (via dragging) to include additional inputs.
Constants
Carriage Return Constant, Empty String Constant, End of Line Constant, Line Feed
Constant, Space Constant, String Constant, Tab Constant
1. Become familiar with the different string constants that are available.
2. Use the String Constant block to create the following constants. Copy & Paste from the
first character of the text for each line to the end of the line.
a. String 1: This is a famous quote from the movie, The Princess Bride:
b. String 2: Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
c. String 3: Have fun stormin' da castle.
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
Basic Functions
Concatenate Strings, Index String Array, Replace Substring, Reverse String, Rotate String,
String Length, String Subset, To Lower Case, To Upper Case, Trim Whitespace
3. Combining strings
a. Use Strings 1 – 3 as the only inputs to the Concatenate Strings block. What is
the length of the resulting string? (Hint: Use the String Length block.)
b. Use Strings 1 – 3 as inputs to the Concatenate Strings block in the manner
shown below. What is the length of the resulting string?
c. Use Strings 1 – 3 as the only inputs the Build Array block (from the Arrays
palette). What is the length of the resulting string?
d. Explain the difference between the output from Parts a – c. What is similar and
what is different about the three results?
4. Use String 1 and the output from 3.c as inputs to the Index String Array block. Create a
control for the index input. Explain how the Index String Array block works. Does the
order of the two input strings matter? Explain.
5. The Replace Substring, Reverse String, Rotate String, String Subset, To Lower Case,
To Upper Case, and Trim Whitespace blocks are all fairly self-explanatory. Read the
Context Help for each block and play around with them enough to understand how each
functions and what information is output.
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
Searching/Matching/Replacing
Match First String, Match Pattern, Match Regular Expression, Match True/False String,
Search and Replace Pattern, Search/Split String
6. Use the Build Array block to create a 1D array of strings with “this”, “This”, “have”, and
“Have” on successive rows.
a. Input String 1 and the 1D array to the Match First String block. What are the
resulting outputs?
b. Input String 2 and the 1D array to the Match First String block. What are the
resulting outputs?
c. Input String 3 and the 1D array to the Match First String block. What are the
resulting outputs?
d. Explain the results for a – c.
7. Investigate how the Match Pattern block works. Compare the Match Pattern and Match
Regular Expression blocks. How do they differ in function? What can you learn from
reading the detailed help for each?
8. Investigate how the Match True/False String block works. What is being examined for a
match? What does each output represent?
9. Place a Search and Replace Pattern block on the block diagram. Create front panel
controls for each of the inputs (except for the Error In). Use the “input string” shown
below, and play around with the other input values, paying attention to the corresponding
outputs.
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
Jeepers, creepers, where’d
you get those peepers?
Explain how the block functions.
10. Investigate and explain how the Search/Split String function works.
Additional String Functions
Append True/False String, Pick Line
11. Investigate and explain how the Append True/False String function works.
12. Investigate and explain how the Pick Line function works.
Formatting/Conversion
Decimal String To Number, Number To Decimal String, Fract/Exp String To Number,
Number to Fractional String, Format Value, Format Into String, Path to Array of Strings, Path
to String, String To Path, Array of Strings to Path
13. Place a Number To Decimal String block on the block diagram and create controls for
each of the inputs and an indicator for the output. Investigate and explain how the block
works. What is the representation (data type) of the output? What is the meaning of the
term “decimal” in the name of the block?
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
14. Use the output from the Number To Decimal String block as the input to the Decimal
String To Number block. Investigate and explain how the Decimal String To Number
block works.
15. Place a Number To Fractional String block on the block diagram and create controls for
each of the inputs and an indicator for the output. Investigate and explain how the block
works.
16. Use the output from the Number To Fractional String block as the input to the Fractional
String To Number block. Investigate and explain how the Fractional String To Number
block works.
17. Investigate and explain how the Format Value block works.
18. Investigate and explain how the Format Into String block works.
19. LabVIEW makes a distinction between the text associated with a file path and a
standard text string. On the block diagram, right-click to open the functions palette.
Click on the Search button and type in “Path Constant”. Place a Path Constant block on
the block diagram. Copy and paste the following text into the path constant:
C:\Program Files (x86)\National Instruments\LabVIEW 2011\LabVIEW.exe
a. Use the output from the Path Constant block as the input to both the Path to
Array of Strings and Path To String blocks. Explain how each block processes
the input.
b. Create a valid file path using both the String To Path and Array of Strings to Path
blocks. Explain the role of the Boolean input to these blocks.
Unit 4 – Common Data Structures
Engineering Computations with LabVIEW
Assignment 4-2-1: Strings Review
Download