Overview
Turn a comma-separated list of tags typed by users into clean, lowercase tags in Go with strings.Split, TrimSpace and ToLower, skipping empty pieces.
- strings.Split, TrimSpace, ToLower
- splitting "" gives one empty item
- skip empty pieces
Short Course
strings.Split, TrimSpace and ToLower clean up user input. Trap:
splitting an empty string gives one empty item, [""], not an empty slice, so
skip empty pieces.
strings.Split("go,web", ",") // [go web]
len(strings.Split("", ",")) // 1, not 0
strings.TrimSpace(" Go ") // "Go"
Task
Write ParseTags(input string) []string: split on commas, trim spaces,
lowercase, and skip empty tags. Example: ParseTags("Go, Web ,,API") →
[go web api].
Test Suites
Pending
Next
Output