Is there a stdlib equivalent of this method?
func Join(sep string, values ...interface{}) string {
strs := make([]string, len(values))
for i, v := range values {
strs[i] = fmt.Sprintf("%s", v)
}
return strings.Join(strs, sep)
}
The strings
package has a Join
method, but it only joins a string slice. I feel like the fmt package could have something like this, I don't know all the % variables that exist.
Is there an stdlib equivalent of this method?
No there is not.
func StrConvert(a ...interface{}) string {
str := ""
for index := 0; index < len(a); index++ {
str1 := fmt.Sprintf("%v", a[index])
str += " " + str1
}
return str
}
you can pass []interface to above function and it will return a string as a response.