Answers for "prints struct in custom format in golang"

Go
0

prints struct in custom format in golang

type T struct {
	a int
	b float64
	c string
}

func (t *T) String() string {
	return fmt.Sprintf("%d____%g____%q", t.a, t.b, t.c)
}

func customFormat() {
	t := &T{ 7, -2.35, "abc" }
	fmt.Printf("%v\n", t)	// output: 7____-2.35____"abc"
}
// default format: &{7 -2.35 abc}
// custom format: 7____-2.35____"abc"
Posted by: Guest on July-03-2021

Code answers related to "prints struct in custom format in golang"

Browse Popular Code Answers by Language