如何在布尔转换一个字符串? [英] How to convert a bool to a string in Go?

查看:84
本文介绍了如何在布尔转换一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将名为 isExist bool 转换为字符串 true false ) c $ c>但它不起作用。什么是Go的惯用方法?

I am trying to convert a bool called isExist to a string (true or false) by using string(isExist) but it does not work. What is the idiomatic way to do this in Go?

推荐答案

使用strconv包

文档

strconv.FormatBool(v)


func FormatBool(b bool)string FormatBool返回true或根据b的值

func FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b

这篇关于如何在布尔转换一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆