Go Printf("%q")

(Go Printf() %q에서 넘어옴)

1 개요[ | ]

Go Printf() %q
Go fmt.Printf("%q")
package main

import "fmt"

func main() {
	message := `hello "world"`

	// invalid json string
	fmt.Printf(`{"message":"%s"}`, message) // {"message":"hello "world""}
	fmt.Println()

	fmt.Printf(`{"message":%s}`, message) // {"message":hello "world"}
	fmt.Println()

	// ok
	fmt.Printf(`{"message":%q}`, message) // {"message":"hello \"world\""}
	fmt.Println()
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}