According to the answer at How to split a string and assign it to variables in Golang? splitting a string results in an array of strings where the separator is not present in any of the strings in the array. Is there a way to split strings such that the separator is on the last line of a given string?
e.x.
s := strings.split("Potato:Salad:Popcorn:Cheese", ":")
for _, element := range s {
fmt.Printf(element)
}
outputs:
Potato
Salad
Popcorn
Cheese
I wish to output the following instead:
Potato:
Salad:
Popcorn:
Cheese
I know I could theoretically append ":" to the end of each element except for the last, but I'm looking for a more general, elegant solution if possible.