40 likes | 132 Vues
Learn how to parse and distinguish the four cases in handling names correctly to avoid errors and confusion. Follow specific tips to recognize and address each case accurately.
E N D
Parsing a Name Homework 1
Cases to Consider • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix • Others??? • Question: how do we tell the computer to recognize and distinguish each case from the others?
Distinguishing the Four Cases Case Distinguishing Characteristic No Comma present First Comma before First Space First Space before First Comma First Comma ≠ Last Comma • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix • Note that one must remove extraneous white space before the strategy above works correctly • Remove leading and trailing whitespace • Replace multiple consecutive whitespace characters with single space • Remove any whitespace immediately before a comma
Distinguishing the Four Cases Case Distinguishing Characteristic No Comma present First Comma before First Space First Space before First Comma First Comma ≠ Last Comma • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix After handling the suffix in the last two cases and then removing it along with its preceding comma and space, we are left with the first two cases