英文:
How come I can use ' and not " in function that requires a byte type
问题
在浏览一些帖子时,我看到有人使用了函数reader.ReadString('\n'),我注意到该帖子使用了'而不是"。这是怎么回事?除了这种情况,这个用法还可以应用在其他地方吗?
英文:
Why scrolling through some posts I saw someone using the function reader.ReadString('\n') I noticed the post used ' instead of ". What's going on here? And can this be applied anywhere else besides this situation?
答案1
得分: 1
单引号 '' 表示rune字面量,而双引号 "" 和反引号 `` 表示string字面量。bufio.Reader.ReadString接受一个byte,可以用单字节的rune字面量表示,例如 '\n'。
英文:
Single quotes '' denote rune literals while double-quotes "" and backticks `` denote string literals. bufio.Reader.ReadString takes a byte, which can be represented by a single-byte rune literal such as '\n'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论