From 3889bee1314924775a4a2f2e5847c82f8f8fadb3 Mon Sep 17 00:00:00 2001 From: Jiepeng Cao Date: Thu, 1 Mar 2018 22:52:37 +0800 Subject: [PATCH 1/3] typo --- ch1-basic/ch1-03-array-string-and-slice.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch1-basic/ch1-03-array-string-and-slice.md b/ch1-basic/ch1-03-array-string-and-slice.md index 0b26d8c..5c68bbc 100644 --- a/ch1-basic/ch1-03-array-string-and-slice.md +++ b/ch1-basic/ch1-03-array-string-and-slice.md @@ -281,9 +281,9 @@ func forOnString(s string, forBody func(i int, r rune)) { **`[]byte(s)`转换模拟实现** ```go -func str2bytes(s []byte) []bytes { +func str2bytes(s string) []byte { p := make([]byte, len(s)) - for i, c := []byte(s) { + for i, c := range []byte(s) { p[i] = c } return p From 67c43df4288ed0c913762563ce305d372e85bae7 Mon Sep 17 00:00:00 2001 From: Jiepeng Cao Date: Thu, 1 Mar 2018 23:03:02 +0800 Subject: [PATCH 2/3] Update ch1-03-array-string-and-slice.md --- ch1-basic/ch1-03-array-string-and-slice.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ch1-basic/ch1-03-array-string-and-slice.md b/ch1-basic/ch1-03-array-string-and-slice.md index 5c68bbc..8b8b732 100644 --- a/ch1-basic/ch1-03-array-string-and-slice.md +++ b/ch1-basic/ch1-03-array-string-and-slice.md @@ -283,7 +283,8 @@ func forOnString(s string, forBody func(i int, r rune)) { ```go func str2bytes(s string) []byte { p := make([]byte, len(s)) - for i, c := range []byte(s) { + for i := 0; i < len(s); i++ { + c := s[i] p[i] = c } return p From 8e8ee0cb75e784c31065316bc3cfc9e7d23a28a8 Mon Sep 17 00:00:00 2001 From: Jiepeng Cao Date: Thu, 1 Mar 2018 23:08:23 +0800 Subject: [PATCH 3/3] typo bytes2str --- ch1-basic/ch1-03-array-string-and-slice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch1-basic/ch1-03-array-string-and-slice.md b/ch1-basic/ch1-03-array-string-and-slice.md index 8b8b732..d9d98b4 100644 --- a/ch1-basic/ch1-03-array-string-and-slice.md +++ b/ch1-basic/ch1-03-array-string-and-slice.md @@ -299,7 +299,7 @@ func str2bytes(s string) []byte { func bytes2str(s []byte) (p string) { data := make([]byte, len(s)) for i, c := s { - p[i] = c + data[i] = c } hdr := (*reflect.StringHeader)(unsafe.Pointer(&p))