-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo09.go
74 lines (64 loc) · 1.58 KB
/
go09.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
package main
import (
"fmt"
"unicode/utf8"
)
func main() {
fmt.Println("姓名:向洪林\n年龄:25")
fmt.Println(`姓名:向洪林\n年龄:25`) // 使用``进行转义输出
fmt.Println(`姓名:向洪林
年龄:25`)
goDir := `C:\go`
fmt.Println("go安装路径:", goDir)
fmt.Println("go安装路径:C:\\go")
// unicode
var pi rune = 960
var alpha rune = 940
var omega rune = 969
var bang byte = 33
fmt.Printf("%v %v %v %v\n", pi, alpha, omega, bang)
// 输出code point
fmt.Printf("%c %c %c %c\n", pi, alpha, omega, bang)
// 自定义类型
type cfloat = float32
type crune = int
var cf cfloat = 1.0
fmt.Printf("%.2f\n", cf)
str := "my name is jonny 向"
//len
fmt.Println("str bytes len:", len(str))
fmt.Println("str len:", utf8.RuneCountInString(str))
r, size := utf8.DecodeRuneInString(str)
fmt.Printf("char:%c code:%v size:%v", r, r, size)
//range
for _, c := range str {
fmt.Printf("%c\n", c)
}
// 作业题
homework09Part1()
fmt.Println("========作业题2=======")
homework09Part2()
}
func homework09Part1() {
const str = "L fdph,L vdz,L frqtxhuhg"
var decodeStr string
for i := 0; i < len(str); i++ {
fmt.Printf("%c", str[i]-3)
}
for i := 0; i < utf8.RuneCountInString(str); i++ {
decodeStr += string(str[i] - 3)
}
fmt.Println("decode str value is ", decodeStr)
}
func homework09Part2() {
const str = "Hola Estación Espacial Internacional"
var encodeStr string
for _, c := range str {
if c < 'A' || c > 'z' {
encodeStr += string(c)
} else {
encodeStr += string(c + 13)
}
}
fmt.Println("encode str value is ", encodeStr)
}