1. 程式人生 > >golang 字符串與int類型轉換

golang 字符串與int類型轉換

pro 類型轉換 ima src 圖片 ring 執行 mac image

一、字符串轉int
func Atoi(s string) (int, error)

案例:
技術分享圖片
執行結果:
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  go build int_string.go
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  ./int_string
int, 100

二、int轉字符串
func Itoa(i int) string

技術分享圖片

執行結果:
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  go build int_string.go
sf@SFdeMacBook-Pro  ~/Documents/project/src/test  ./int_string

string,100

golang 字符串與int類型轉換