Introduction
In this challenge, participants are tasked with implementing a function to format user names in a social media platform's user registration system. The goal is to ensure consistent and clean user input for data integrity and user experience. Specifically, the function should trim leading and trailing whitespaces, capitalize the first letter of each name segment, and handle multiple name segments (first, middle, last names).
Process User Registration Strings
In a social media platform's user registration system, maintaining consistent and clean user input is crucial for data integrity and user experience.
Tasks
- Create a function
formatUserNamethat takes a full name as input - Trim leading and trailing whitespaces from the input
- Capitalize the first letter of each name segment
- Return the formatted full name
Requirements
- Create the solution in
~/project/registration.go - Use Go's string manipulation functions from previous lab
- Function must handle multiple name segments (first, middle, last names)
- Use
strings.TrimSpace()to remove extra whitespaces - Ensure the function works with various input formats
Examples
To test the function, update the main() function with some example cases:
func main() {
fmt.Println(formatUserName(" john doe ")) // Output: John Doe
fmt.Println(formatUserName(" alice bob smith ")) // Output: Alice Bob Smith
fmt.Println(formatUserName("JANE DOE")) // Output: Jane Doe
}
Run the program and verify the output matches the expected results.
go run registration.go
John Doe
Alice Bob Smith
Jane Doe
Hints
strings.TrimSpace()removes leading and trailing whitespaces from the input namestrings.Fields()splits the name into segments, handling multiple spacesstrings.ToLower()ensures consistent capitalization before applyingTitle()strings.Join()reconstructs the formatted name with a space between segments
Summary
In summary, this challenge requires participants to implement a function that formats user names in a social media platform's user registration system. The function should trim leading and trailing whitespaces, capitalize the first letter of each name segment, and handle multiple name segments (first, middle, last names). The goal is to ensure consistent and clean user input for data integrity and user experience.



