Re: [go-nuts] Re: How to print arrays with commas and brackets

2020-08-07 Thread Henry
First, there is no such requirement in the OP's original post and there is no mention whether the output is going to be used for another processing that requires character escaping. The correctness of a solution is judged against its requirements. Second, judging from the OP's question, it

Re: [go-nuts] Re: How to print arrays with commas and brackets

2020-08-07 Thread Kurtis Rader
On Fri, Aug 7, 2020 at 7:46 PM Henry wrote: > Or you can do it manually: > > func print(array []string) string { > var buffer strings.Builder > buffer.WriteString("[") > for index, item := range array { > if index != 0 { > buffer.WriteString(", ") > } > buffer.WriteString("\"" + item + "\"") > }

[go-nuts] Re: How to print arrays with commas and brackets

2020-08-07 Thread Henry
Or you can do it manually: func print(array []string) string { var buffer strings.Builder buffer.WriteString("[") for index, item := range array { if index != 0 { buffer.WriteString(", ") } buffer.WriteString("\"" + item + "\"") } buffer.WriteString("]") return buffer.String() } On Wednesday,

[go-nuts] Re: How to print arrays with commas and brackets

2020-08-07 Thread Henry
Or you can do it manually: func print(array []string) string { var buffer strings.Builder buffer.WriteString("[") for index, item := range array { if index != 0 { buffer.WriteString(", ") } buffer.WriteString("\"" + item + "\"") } buffer.WriteString("]") return buffer.String() } On Wednesday,

Re: [go-nuts] Re: How to print arrays with commas and brackets

2020-08-06 Thread Raffaele Sena
One option is to use json.Marshal or json.Encoder.Encode fmt.Printf("%q", []string{"Hello", "world", "!") would quote the separate strings and put the square brackets, but doesn't comma separate the items. On Thu, Aug 6, 2020 at 9:24 AM wrote: > Hello Michele > > This won't print in the array

[go-nuts] Re: How to print arrays with commas and brackets

2020-08-06 Thread ranjan1234biswa
Hello Michele This won't print in the array format rather it would print it in other way. stringArray := []string{"Hello", "world", "!"} fmt.Printf("[%s]", strings.Join(stringArray , ",")) Output [Hello,world,!] On Thursday, October 10, 2019 at 10:41:59 PM UTC+5:30, Michele Caci