当前位置:网站首页>GO语言:字符串的连接、数字转化字符串
GO语言:字符串的连接、数字转化字符串
2022-06-11 08:19:00 【淡灰灰灰】
连接字符串
1.GO语言类似python,可以直接用'+'加号直接连接字符串。
2.也可以用fmt.Sprintf()格式化输出的方式临时拼接:fmt.Sprintf("%s%s",s1,s2)。
3.跟python一样也可以用Join函数。
数字转化字符串
1.fmt.Println(string(num))可以将数字作为字符输出
2.但是有时候我们会需要直接将数字转化为字符串:
使用strconv实现,看示例
以下示例:
package main
import (
"fmt"
"strconv"
)
func main() {
var num int = 10 // 数字10
var mbti string = ""
mbti = mbti + "I"
mbti = mbti + "N"
mbti = mbti + "T"
mbti = mbti + "P"
fmt.Printf("%d,%s,%s", num, strconv.Itoa(num), mbti)
}
运行结果如下:
10,10,INTP边栏推荐
- node报错整理
- Uniapp turn off / on / adjust system sound
- Use of Excel to XML tool of TestLink
- Scrape captures 51job Recruitment Information (static page)
- TypeScript-类型保护
- Typescript interface and type alias similarities and differences
- Js基础学习Script
- TypeScript-分布式条件类型
- Process control: process waiting (recycling child processes)
- Icml2022 article intéressant
猜你喜欢

centos随笔03:centos8.2安装mysql

Space geometry

不想项目失控?你需要用对项目管理工具

Study the Analects of entanglement

Scrape captures 51job Recruitment Information (static page)

Difference between threadpooltaskexecutor and ThreadPoolExecutor

What does it mean to buy a single-mode, dual-mode and Rechargeable Wireless Mouse

进程控制:进程等待(回收子进程)

Reference implementation scheme of database database and table division strategy

Bubble sorting with C language
随机推荐
In an activity, view postdelay will cause memory leakage, but will not affect the life cycle execution of the activity.
Collation of basic knowledge of intermediate development of Andrews (for interview)
Use Jackson's @jsonproperty annotation to add one more field to the property name. Solution to the problem
Typescript unknown type
Clipping and overlapping of YUV data
Record a murder case caused by ignoring the @suppresslint ("newapi") prompt
Empty difference between postgrepsql and Oracle
How to find the complementary sequence of digraph
How to make hyperlinks in RichTextBox- How can I make a hyperlink work in a RichTextBox?
Typescript declaration merge
134. gas station
Node error report sorting
Printing diamond of beginner C
Return in foreach and break in for
2022.6.7 special student simulation
项目实训-克隆门
AttributeError: module ‘tensorflow. compat. v2.__ internal__‘ has no attribute ‘register_ clear_ session_
Modifying field length in Oracle and postgrepsql
These gadgets are also very easy to use
The role of lambdalr in pytorch