Scanner.Scan()runeScanner.Scan()Scanner.Moderunetext/scanner
runeScanner.Next()
c := b.Next()
fmt.Println(c, string(c), strconv.QuoteRune(c))
输出:
97 a 'a'
runestringruneint32string
将有符号或无符号整数值转换为字符串类型会生成一个包含整数的UTF-8表示形式的字符串.
因此:
r := rune('a')
fmt.Println(r, string(r))
输出:
97 a
stringfor ... range
for i, r := range "abc" {
fmt.Printf("%d - %c (%v)\n", i, r, r)
}
输出:
0 - a (97)
1 - b (98)
2 - c (99)
string[]rune
fmt.Println([]rune("abc")) // 输出: [97 98 99]
试试看Go Playground号公路上的例子.
Note:
Scanner.Scan()
c := b.Scan()
if c == scanner.Ident {
fmt.Println("Identifier:", b.TokenText())
}
// 输出: "Identifier: a"