On Wed, 2019-10-09 at 06:02 -0700, Nalin Pushpakumara wrote:
> Hi,
> I tried to print array with brackets and commas in golang. I want to
> get
> array like this.
> ["record1", "record2". "record3"]
>
> Does anyone know how to do it?
>
> Thank you
>
Not the most efficient, but simple and clear.
func printSlice(a []string) string {
q := make([]string, len(a))
for i, s := range a {
q[i] = fmt.Sprintf("%q", s)
}
return fmt.Sprintf("[%s]", strings.Join(q, ", "))
}
https://play.golang.org/p/cn9EaL0x-2v
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/42f2c00adc67d6100724122d93e8467513ecee12.camel%40kortschak.io.