golang interface 转 string,int,float64
inter 是interface类型,转化为string类型是:
str := inter.(string)
转为其他类型也类似
testInt := inter.(int)
testFloat := inter.(float64)
示例如下:
func interface2String(inter interface{}) {switch inter.(type) {case string:fmt.Println("string", inter.(string))breakcase int:fmt.Println("int", inter.(int))breakcase float64:fmt.Println("float64", inter.(float64))break}}func main() {interface2String("jack")interface2String(1)interface2String(12.223)
}
输出结果:
string jack
int 1
float64 12.223
golang interface 转 string,int,float64相关推荐
- golang interface 转 int string slice struct 类型
在golang中,interface{}允许接纳任意值,int, string, struct,slice等,因此我可以很简单的将值传递到interface{} package main import ...
- golang string int int32 int64 float32 float64 time 互相转换
目录 1.float64转int int转int64 2.string和int.int32.int64 3.string和float32.float64 4.string和time 5.转换函数说明 ...
- Golang interface 接口详细原理和使用技巧
文章目录 Golang interface 接口详细原理和使用技巧 一.Go interface 介绍 interface 在 Go 中的重要性说明 interface 的特性 interface 接 ...
- go golang 中获取string 长度
新博客地址(shankusu.me) 以下内容转自自 https://blog.csdn.net/skh2015java/article/details/53258249 一.获取字符串长度的几种方法 ...
- The constructor JedisPool(GenericObjectPoolConfig, String, int, int, String) refers to the missing t
想学习学习redis缓存技术,于是到网上copy到了一些代码,粘贴到ecplise上面,但是发现代码总是报错 The constructor JedisPool(GenericObjectPoolCo ...
- java中String,int,Integer,char、double类型转换
java中String,int,Integer,char.double类型转换----https://www.cnblogs.com/kangyu222/p/5866025.html 转载于:http ...
- 如何解决提示the operation % is undefined for the argument type string,int的错误
今天在做一个用三元运算符判断奇偶的小练习时遇到"the operation % is undefined for the argument type string,int"错误的小 ...
- golang []byte 和 string相互转换
原文链接:golang []byte和string相互转换 测试例子 package mainimport ("fmt" )func main() {str2 := "h ...
- String int之间转换
String int之间转换
最新文章
- oracle 截取字段长度substr
- Spring5 - 核心原理
- Oracle单行函数
- vue2.0s中eventBus实现兄弟组件通信
- 浙大网新实训项目介绍
- HTML小知识点积累
- SAP Fiori里的Adapt UI按钮,神出鬼没的奥秘
- 有道智能学习灯 初体验
- Spring笔记——数据源配置
- 数据库笔记11:创建与管理存储过程
- 接口测试工具--Apipost不同脚本的作用
- 接入微信分享过程的喜和泪
- uCOS-II 学习笔记之任务管理--------任务控制块OS_TCB
- python爬虫实战万年历
- 同时删除多个 Word 文档空白行
- 60个英文阅读网站强力推荐
- oracle 挖掘日志,使用Oracle的Logminer工具进行日志挖掘
- JAVA手机验证码的生成简单实现
- 应用程序如何从X86快速换到ARM架构 | 瑞迅科技工控一体机解读
- 编程笔试(解析及代码实现):求和为N的正整数序列之实现一个函数,输入为一个正整数N (比如100),输出为所有和等于N的[连续]正整数序列