docs: String 字符串

This commit is contained in:
Shikong 2021-09-13 01:44:46 +08:00
parent 0b8021a283
commit b73977b97d

31
base/string/main.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"fmt"
)
func main() {
// golang 中 字符串 使用 双引号 包裹
// 字符串为 string 类型
s1 := "Hello World!"
// golang 中 单个字符(中文、字符、符号) 使用 单引号 包裹
// 单字符为 rune 类型, rune 为 int32 别名
c1 := '你'
c2 := '好'
c3 := ','
c4 := '世'
c5 := '界'
fmt.Printf("s1: %s\n", s1)
fmt.Printf("c1: '%c'\tc2: '%c'\tc3: '%c'\tc4: '%c'\tc5: '%c'\n", c1, c2, c3, c4, c5)
fmt.Println("=========================================================")
// []rune 字符数组
r1 := []rune{c1, c2, c3, c4, c5}
// rune 转 string
s2 := string(r1)
fmt.Printf("s2: %s\n", s2)
}