加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在golang中的一个字符串中插入一个数字

发布时间:2020-12-16 19:18:15 所属栏目:大数据 来源:网络整理
导读:package mainimport ( "fmt")func main() { fmt.Println(say(9))}func say(num int)(total string){return fmt.Sprintf("There are %s reasons to code!",num)} 我的输出是 There are %!s(int=9) reasons to code! 我应该如何在字符串中插入一个数字? 如果
package main

import (
    "fmt"
)

func main() {
    fmt.Println(say(9))
}

func say(num int)(total string){
return fmt.Sprintf("There are %s reasons to code!",num)
}

我的输出是

There are %!s(int=9) reasons to code!

我应该如何在字符串中插入一个数字?

如果要始终使用“默认”表示,无论使用什么类型,请使用%v作为in
fmt.Sprintf("There are %v reasons to code!",num)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读