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
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 + "\"")
> }
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,
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,
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
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