Go []byte数组/int转化为string
发布日期:2021-11-14 04:12:09 浏览次数:3 分类:技术文章

本文共 546 字,大约阅读时间需要 1 分钟。

Go 语言中读取[]byte数组,获取到的数组元素类型会是int,eg:

package mainimport (	"fmt")type IPAddr [4]bytefunc main() {    test := IPAddr{123,'T',3,1}    temp := test[0]    fmt.Printf("%T %v\n", temp, temp)	temp = test[1]    fmt.Printf("%T %v", temp, temp)}输出:uint8 123uint8 84

将int类型转换为string,eg:

package mainimport (	"fmt"	"strconv")type IPAddr [4]bytefunc main() {    test := IPAddr{123,12,3,1}    result := ""    for i:=0;i

将字符转化为string,eg:

package mainimport (	"fmt")type IPAddr [4]bytefunc main() {    test := IPAddr{'T','e','s','t'}    result := ""    for i:=0;i

 

转载地址:https://blog.csdn.net/meng_dream_fly/article/details/102570223 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Postman 提交数组和json
下一篇:memcached基本操作

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月02日 00时47分27秒