Strings, bytes, runes and characters in Go - The Go Programming Language
Strings, bytes, runes and characters in Go - The Go Programming Language
11
公开标注数
7
参与人数
2026-07-25 10:01:10
首次 Whisper
讨论活跃度
go.dev 近 17 周的公开 Whisper
少多
最新公开 Whisper
划选高亮2026-07-26 16:25:15
原文高亮摘录
“Even though the slice header is passed by value”
Whisper 随想笔记
This is exactly why slices feel like references even though they're not.
划选高亮2026-07-26 13:22:15
原文高亮摘录
“s important to understand that even though a slice contains a pointer”
Whisper 随想笔记
So it's like a struct with a pointer inside? That actually clears things up.
划选高亮2026-07-26 13:13:15
原文高亮摘录
“s important to understand that even though a slice contains a pointer”
Whisper 随想笔记
Yeah, took me a while to get that slices are values, not just pointers.
划选高亮2026-07-26 10:19:15
原文高亮摘录
“A slice is not an array.”
Whisper 随想笔记
Yeah, but honestly the distinction only bites you when you mess with append too much.
划选高亮2026-07-26 10:10:15
原文高亮摘录
“A slice is not an array.”
Whisper 随想笔记
Always forget this—then I wonder why changing a slice changes the original array.
划选高亮2026-07-26 10:01:15
原文高亮摘录
“A slice is not an array.”
Whisper 随想笔记
Wait, so a slice is like a view into an array, not the array itself? Mind blown.
划选高亮2026-07-25 13:22:10
原文高亮摘录
“Some people think Go strings are always UTF-8”
Whisper 随想笔记
That's a common gotcha, but the docs make it pretty clear if you read carefully.
划选高亮2026-07-25 13:13:10
原文高亮摘录
“Some people think Go strings are always UTF-8”
Whisper 随想笔记
Wait, so my string can have random bytes? I thought Go was all UTF-8 man.
划选高亮2026-07-25 10:19:10
原文高亮摘录
“In Go, a string is in effect a read-only slice of bytes.”
Whisper 随想笔记
This clicked for me after fighting with UTF-8 for an hour.
划选高亮2026-07-25 10:10:10
原文高亮摘录
“In Go, a string is in effect a read-only slice of bytes.”
Whisper 随想笔记
Wait, does that mean string concat is just appending to a new slice?
划选高亮2026-07-25 10:01:10
原文高亮摘录
“In Go, a string is in effect a read-only slice of bytes.”
Whisper 随想笔记
So basically strings are just byte slices you can't modify, got it.