Last active
May 19, 2017 14:46
-
-
Save sekky0905/ba5a49831727902f48dcbd9757f89325 to your computer and use it in GitHub Desktop.
Go言語の便利なfmt.Sprintf ~任意の型と文字列をまとめて文字列(string型に)~ ref: http://qiita.com/Sekky0905/items/5a65602dce83551184b3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
年齢26 | |
身長170 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
年齢:26 | |
身長:170 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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