关于golang:Go-语言的字符串使用

36次阅读

共计 359 个字符,预计需要花费 1 分钟才能阅读完成。

定义字符串

# 一般字符串
name := "lilei"

# 多行字符串
usage := `hello,
my name is lilei
i'm a boy.`

fmt.Println("name:", name)
fmt.Println("usage:", usage)

字符串长度及遍历字符串

name := "lilei"
nameLen := len(name)
fmt.Println("name length:" nameLen)

for i := 0; i < len(name); i++ {fmt.Printf("i: %d, v: %c\n", i, name[i])
}

拼接字符串

i, j := "hello", "world"
fmt.Println("i+j=", i+j)

定义常量

const ADDRESS := "beijing"
fmt.Println("address:", ADDRESS)

正文完
 0