Skip to content

Instantly share code, notes, and snippets.

@sekky0905
Last active May 19, 2017 14:46
Show Gist options
  • Save sekky0905/ba5a49831727902f48dcbd9757f89325 to your computer and use it in GitHub Desktop.
Save sekky0905/ba5a49831727902f48dcbd9757f89325 to your computer and use it in GitHub Desktop.
Go言語の便利なfmt.Sprintf ~任意の型と文字列をまとめて文字列(string型に)~ ref: http://qiita.com/Sekky0905/items/5a65602dce83551184b3
package main
import (
"fmt"
)
func main() {
type Person struct {
Age int
Height int
}
p := new(Person)
p.Age = 26
p.Height = 170
fmt.Printf("年齢%d\n身長%d", p.Age, p.Height)
}
年齢26
身長170
package main
import (
"fmt"
)
func main() {
type Person struct {
Age int
Height int
}
p := new(Person)
p.Age = 26
p.Height = 170
str := fmt.Sprintf("年齢:%d\n身長:%d", p.Age, p.Height)
fmt.Println(str)
}
年齢:26
身長:170
package main
import (
"fmt"
)
func main() {
type Person struct {
Age int
Height int
}
p := new(Person)
p.Age = 26
p.Height = 170
str := fmt.Sprintf("年齢:%d\n身長:%d", p.Age, p.Height)
fmt.Println(str + "\n" + "ハンドルネーム:Sekky0905")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment