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 appears that the OP is 
relatively new to Go or perhaps the field of programming in general and 
he/she is looking for a simple algorithm to guide him/her through. If you 
were to offer a sophisticated solution, you are not helping the OP. 

Finally, it should be relatively easy for the OP to build upon the given 
solution and tailor it to his/her needs, and whether the OP would like to 
escape certain characters or format it in any other way.

On Saturday, August 8, 2020 at 9:53:09 AM UTC+7, Kurtis Rader wrote:
>
> On Fri, Aug 7, 2020 at 7:46 PM Henry <henry.a...@gmail.com <javascript:>> 
> 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 + "\"")
>> }
>> buffer.WriteString("]")
>> return buffer.String()
>> }
>>
>
> Consider what is emitted if the item contains a double-quote rune. In 
> other words, your solution is naive and only produces unambiguous, correct, 
> output for a subset of cases.
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0bed9278-c71e-4ea3-862c-2e8f26ad05e4o%40googlegroups.com.

Reply via email to