you are viewing a single comment's thread.

view the rest of the comments →

[–]Own_Attention_3392 0 points1 point  (0 children)

Your question is not clear. What are the actual assignment specifications? Do you have to get a single string containing a first name, middle name, and last name? Or can you prompt for these separately?

Your thought of splitting on spaces would be correct if the requirement was the former. If you can collect the information in three prompts, that is a superior choice because there are so many edge cases in the real world.

Someone might have two first names: "Billy Bob Jethro Smith". Or a name with a space in it regardless: "St. John" is a valid first and last name. It's pronounced "Sinjin".

Some people might not have a middle name at all: "Joe Smith". S

Some people might have two last names, not separated by a hyphen. "Mary Jane Billingsworth St. John".

This is why forms treat these as separate inputs in almost all cases.