drvntaomy06331839 2015-03-16 07:01
浏览 510
已采纳

在Golang中实现动态字符串

I have following global string,

studentName := "Hi ? ,Welcome"

Now I want to take this string dynamically

func returnName(name string) string{
    return studentName+name
}

This function should return string as

Hi name,welcome.

string should take name from parameter,and return dynamic string.What is the best way to implement this in golang.

  • 写回答

4条回答 默认 最新

  • donglong9745 2015-03-16 08:05
    关注

    If you want to keep things simple, you can probably just use fmt.Sprintf.

    studentName := fmt.Sprintf("Hi, %s! Welcome.", name)
    

    The %s part will get replaced by the value of name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图