Files
the-way-to-go_ZH_CN/eBook/18.2.md
songleo 7c06912c30 modified: 18.1.md
new file:   18.10.md
	new file:   18.11.md
	new file:   18.2.md
	new file:   18.3.md
	new file:   18.4.md
	modified:   18.5.md
	new file:   18.6.md
	new file:   18.7.md
	new file:   18.8.md
	new file:   18.9.md
	modified:   directory.md
2016-01-03 13:53:23 +08:00

46 lines
997 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 18.2 数组和切片
创建: `arr1 := new([len]type)`
`slice1 := make([]type, len)`
初始化:`arr1 := [...]type{i1, i2, i3, i4, i5}`
`arrKeyValue := [len]type{i1: val1, i2: val2}`
`var slice1 []type = arr1[start:end]`
1如何截断数组或者切片的最后一个元素
`line = line[:len(line)-1]`
2如何使用`for`或者`for-range`遍历一个数组(或者切片):
```go
for i:=0; i < len(arr); i++ {
= arr[i]
}
for ix, value := range arr {
}
```
3如何在一个二维数组或者切片arr2Dim中查找一个指定值V
```go
found := false
Found: for row := range arr2Dim {
for column := range arr2Dim[row] {
if arr2Dim[row][column] == V{
found = true
break Found
}
}
}
```
## 链接
- [目录](directory.md)
- 上一章:[运算符模板和接口](17.4.md)
- 下一节:[字符串](18.1.md)