how can I convert type []string
to []rune
?
I know you can do it like this:[]rune(strings.Join(array,""))
but is there a better way?
how can I convert type []string
to []rune
?
I know you can do it like this:[]rune(strings.Join(array,""))
but is there a better way?
I would prefer not to use strings.Join(array,"")
for this purpose because it builds one big new string I don't need. Making a big string I don't need is not space-efficient, and depending on input and hardware it may not be time-efficient.
So instead I would iterate through the array of string values and convert each string to a rune slice, and use the built-in variadic append function to grow my slice of all rune values:
var allRunes []rune
for _, str := range array {
allRunes = append(allRunes, []rune(str)...)
}