40 | Filtering Records |
Sorting records is helpful, but sometimes you need to filter down the results to find or display only what you’re looking for.
Given the following data set
First Name | Last Name | Position | Separation date |
---|---|---|---|
John | Johnson | Manager | 2016-12-31 |
Tou | Xiong | Software Engineer | 2016-10-05 |
Michaela | Michaelson | District Manager | 2015-12-19 |
Jake | Jacobson | Programmer | |
Jacquelyn | Jackson | DBA | |
Sally | Weber | Web Developer | 2015-12-18 |
create a program that lets a user locate all records that match the search string by comparing the search string to the first or last name field.
Example Output
| Enter a search string: Jac |
| |
| Results: |
| Name | Position | Separation Date |
| --------------------|-------------------|---------------- |
| Jacquelyn Jackson | DBA | |
| Jake Jacobson | Programmer | |
Constraint ...
Get Exercises for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.