Go语言中的单引号、双引号、反引号
=Start=
搜索关键字:
golang single quotes
golang double quotes
golang back quotes
参考结果:
结论写在最前:在Go语言中不倾向于使用单引号来表示字符串,请根据需要使用双引号或反引号。
一个Go语言字符串是一个任意字节的常量序列。Go语言的字符串类型在本质上就与其他语言的字符串类型不同。Java的String、C++的std::string以及python3的str类型都只是定宽字符序列,而 Go语言的字符串是一个用UTF-8编码的变宽字符序列,它的每一个字符都用一个或多个字节表示 。
Go语言中的字符串字面量使用 双引号 或 反引号 来创建 :
- 双引号用来创建 可解析的字符串字面量 (支持转义,但不能用来引用多行);
- 反引号用来创建 原生的字符串字面量 ,这些字符串可能由多行组成(不支持任何转义序列),原生的字符串字面量多用于书写多行消息、HTML以及正则表达式。
There are two forms: raw string literals and interpreted string literals.
- Raw string literals are character sequences between back quotes, as in
foo
.- Interpreted string literals are character sequences between double quotes, as in “bar”.
A rune literal represents a rune constant, an integer value identifying a Unicode code point. A rune literal is expressed as one or more characters enclosed in single quotes, as in ‘x’ or ‘\n’. Within the quotes, any character may appear except newline and unescaped single quote. A single quoted character represents the Unicode value of the character itself, while multi-character sequences beginning with a backslash encode values in various formats.
=
根据我找到的资料以及碰到的情况来看, Go语言的单引号一般用来表示「rune literal」 ,即——码点字面量。
参考链接:
- https://golang.org/ref/spec#String_literals
- https://golang.org/ref/spec#Rune_literals
- http://teapottable.com/blog/starting-out-with-go-lang/
=EOF=
相关文章
- Golang 【basic_leaming】go mod 以及包详解
- Go程序设计语言1.1 hello,world
- Go程序设计语言1.3 找出重复行
- Go程序设计语言2.2 声明
- Go程序设计语言2.3 变量
- Go程序设计语言2.6 包和文件
- Go程序设计语言2.7 作用域
- 使用 Go 语言实现优雅的服务器重启
- Go语言学习:编译成windows和linux上可执行文件
- Go语言开发小技巧&易错点100例(五)
- Go初始化函数make和new有什么区别?
- 04、GO模块与包、结构体
- 02.Go语言开发环境配置
- GO语言练习:channel 缓冲机制
- Go语言学习(二)
- Go语言 http 中的 request.Host 和 request.URL.Host 的区别
- Go开发中如何进行自定义Response.go封装实现
- 【Go语言入门】一文搞懂Go语言的最新依赖管理:go mod的使用
- Go语言与数据库开发:01-01
- 深入探索Go语言的unsafe包,揭秘它的黑科技和应用场景!
- 通过实战总结的 使用Go语言小技巧
- Go语言中比较优雅的写法
- Go GORM是时候升级新版本了 2.0新特性介绍(2)
- GO语言基础之error
- Go语言_时间篇
- 这你能相信?有人用Java、Python、C、C++、Go、JS等等各种语言把所有算法实现了一遍
- Go 查找