mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
ch1-03: 更新图片
This commit is contained in:
parent
5536342a09
commit
edcba4cba7
@ -158,7 +158,7 @@ type StringHeader struct {
|
||||
|
||||
我们可以看看字符串“Hello, world”本身对应的内存结构:
|
||||
|
||||

|
||||

|
||||
|
||||
分析可以发现,“Hello, world”字符串底层数据和以下数组是完全一致的:
|
||||
|
||||
@ -208,7 +208,7 @@ fmt.Println("\xe7\x95\x8c") // 打印: 界
|
||||
|
||||
下图展示了“Hello, 世界”字符串的内存结构布局:
|
||||
|
||||

|
||||

|
||||
|
||||
Go语言的字符串中可以存放任意的二进制字节序列,而且即使是UTF8字符序列也可能会遇到坏的编码。如果遇到一个错误的UTF8编码输入,将生成一个特别的Unicode字符‘\uFFFD’,这个字符在不同的软件中的显示效果可能不太一样,在印刷中这个符号通常是一个黑色六角形或钻石形状,里面包含一个白色的问号‘<E58FB7>’。
|
||||
|
||||
|
BIN
images/ch1-03-string-1.ditaa.png
Normal file
BIN
images/ch1-03-string-1.ditaa.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
14
images/ch1-03-string-1.ditaa.txt
Normal file
14
images/ch1-03-string-1.ditaa.txt
Normal file
@ -0,0 +1,14 @@
|
||||
hello, world
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|
||||
| ... | h | e | l | l | o | , | | w | o | r | l | d | ... |
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|
||||
^ ^
|
||||
| |
|
||||
+-----------=-+ :
|
||||
| | |
|
||||
+-----+---+ +---+----+ +---+----+
|
||||
| data | | data | | data |
|
||||
+---------+ +--------+ +--------+
|
||||
| len: 12 | | len: 5 | | len: 5 |
|
||||
+---------+ +--------+ +--------+
|
||||
hello, world hello world
|
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB |
BIN
images/ch1-03-string-2.ditaa.png
Normal file
BIN
images/ch1-03-string-2.ditaa.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
5
images/ch1-03-string-2.ditaa.txt
Normal file
5
images/ch1-03-string-2.ditaa.txt
Normal file
@ -0,0 +1,5 @@
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|
||||
| ... | h | e | l | l | o | , | | E4 | B8 | 96 | E7 | 95 | 8C | ... |
|
||||
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|
||||
|
||||
|<-------=- UTF8 Encoding -=-------->|
|
Binary file not shown.
Before Width: | Height: | Size: 9.5 KiB |
Loading…
x
Reference in New Issue
Block a user