-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt-demo.go
79 lines (62 loc) · 1.31 KB
/
fmt-demo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
)
func fmtString(){
testStr := "Hello, Golang"
testRunes := []rune(testStr)
fmt.Printf("string: %s\n", testStr)
fmt.Printf("rune: %s\n", testRunes)
fmt.Printf("string(q): %q\n", testStr)
fmt.Printf("rune(q): %q\n", testRunes)
fmt.Printf("string(x): %x\n", testStr)
fmt.Printf("rune(x): %x\n", testRunes)
fmt.Printf("string(X): %X\n", testStr)
fmt.Printf("rune(X): %X\n", testRunes)
}
func fmtInteger(){
testInt := 128
fmt.Printf("%03d\n", testInt)
fmt.Printf("%-03#b\n", testInt)
fmt.Printf("%-03#o\n", testInt)
fmt.Printf("%#x\n", testInt)
fmt.Printf("%-03#X\n", testInt)
fmt.Printf("%-03#q\n", testInt)
fmt.Printf("%c\n", testInt)
fmt.Printf("%-03#U\n", testInt)
}
func fmtPointer() {
testInt := 128
p := &testInt
fmt.Printf("%p\n", p)
}
func fmtStruct() {
type MyType struct{
Msg string
}
value := MyType{"Hello"}
fmt.Printf("%d\n", value)
fmt.Printf("%s\n", value)
fmt.Printf("%+s\n", value)
fmt.Printf("%+v\n", value)
}
func fmtFloating(){
floatValue := 123.35
fmt.Printf("%6.4G\n", floatValue)
fmt.Printf("%.4f\n", floatValue)
}
func demoScanf(){
var a int
var b string
fmt.Scanf("%d %s", &a, &b)
fmt.Printf("a=%d, b=%s\n", a, b)
}
func main() {
//fmtString()
//fmtInteger()
//fmtPointer()
//fmtStruct()
//fmtFloating()
//demoScanf()
fmtInteger()
}