名词
- 单引号 single quotes
- 双引号 double quotes
- 反引号 back quotes
说明
Go语言的字符串是一个用UTF-8编码的变宽字符序列,它的每一个字符都用一个或多个字节表示 。
区别
- 单引号 不能用来表示字符串
- 双引号 可解析的字符串字面量 (支持转义,但不能用来引用多行);
- 反引号 原生的字符串字面量 ,支持多行,不支持转义, 多用于书写多行消息、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.