TOPIC: One Liner of the Day
#1633
One Liner of the Day 9 Months, 1 Week ago
In some code I was working on, the user was entering a comma separated list of tags/labels (for attachments).

To clean up the input I ended up with:

labels = labels.Split(",").Map!(#Trim).Remove("").Sort!().Unique!().Join(", ")

This splits the string at the commas, trims leading and trailing whitespace from each value, removes any empty values, sorts them, eliminates duplicates, and then joins them back into a string. Pretty good for one line.
 
 
andrew