From 706c594a7e5192a38b9bcd47e8bfe6244c9ec697 Mon Sep 17 00:00:00 2001 From: songleo Date: Sun, 3 Jan 2016 14:49:10 +0800 Subject: [PATCH] modified: eBook/18.1.md modified: eBook/18.11.md modified: eBook/18.2.md modified: eBook/18.3.md --- eBook/18.1.md | 2 +- eBook/18.11.md | 2 +- eBook/18.2.md | 13 +++++++------ eBook/18.3.md | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/eBook/18.1.md b/eBook/18.1.md index d7ca296..00acb7b 100644 --- a/eBook/18.1.md +++ b/eBook/18.1.md @@ -15,7 +15,7 @@ s2:= string(c) // s2 == "cello" substr := str[n:m] ``` -(3)如何使用for或者for-range遍历一个字符串: +(3)如何使用`for`或者`for-range`遍历一个字符串: ```go // gives only the bytes: diff --git a/eBook/18.11.md b/eBook/18.11.md index 996fbaf..8aff0c8 100644 --- a/eBook/18.11.md +++ b/eBook/18.11.md @@ -8,7 +8,7 @@ (4)尽可能的使用数组和切片代替映射(详见 参考文献15); -(5)如果只想获取切片中某项值,不需要值的索引,尽可能的使用`for range`去遍历切片,这比必须去查询切片中的每个元素要快一些; +(5)如果只想获取切片中某项值,不需要值的索引,尽可能的使用`for range`去遍历切片,这比必须去查询切片中的每个元素要快一些; (6)当数组元素是稀疏的(例如有很多0值或者空值),使用映射会降低内存消耗; diff --git a/eBook/18.2.md b/eBook/18.2.md index 72dc42a..164da44 100644 --- a/eBook/18.2.md +++ b/eBook/18.2.md @@ -1,15 +1,16 @@ # 18.2 数组和切片 -创建: `arr1 := new([len]type)` +创建: +`arr1 := new([len]type)` - `slice1 := make([]type, len)` +`slice1 := make([]type, len)` -初始化:`arr1 := [...]type{i1, i2, i3, i4, i5}` +初始化: +`arr1 := [...]type{i1, i2, i3, i4, i5}` - `arrKeyValue := [len]type{i1: val1, i2: val2}` - - `var slice1 []type = arr1[start:end]` +`arrKeyValue := [len]type{i1: val1, i2: val2}` +`var slice1 []type = arr1[start:end]` (1)如何截断数组或者切片的最后一个元素: diff --git a/eBook/18.3.md b/eBook/18.3.md index c260eee..1f1d750 100644 --- a/eBook/18.3.md +++ b/eBook/18.3.md @@ -16,7 +16,7 @@ for key, value := range map1 { `val1, isPresent = map1[key1]` -返回值: 键`key1`对应的值或者`0`, `true`或者`false` +返回值:键`key1`对应的值或者`0`, `true`或者`false` (3)如何在映射中删除一个键: