NotePublic/Software/Development/Language/Go/Basic/Go_语言字符串操作.md

25 lines
383 B
Markdown
Raw Normal View History

# Go 语言字符串操作
## 1.分割/拼接操作
```go
// 1. 以 "," 对字符串分割
s:="A,B,C"
parts:=strings.Split(s,",")
fmt.Println(parts)
// 2. 把字符串连接起来
s=strings.Join(parts,"-")
fmt.Println(s)
```
## 2.字符串和其他类型转换
```go
// 数字转字符串
s=strconv.Itoa(10)
fmt.Println(s)
// 字符串转整形
fmt.Println(strconv.Atoi(s))
```