mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 17:36:12 +08:00
modified: eBook/18.1.md
This commit is contained in:
@@ -29,15 +29,18 @@ for ix, ch := range str {
|
|||||||
```
|
```
|
||||||
|
|
||||||
(4)如何获取一个字符串的字节数:`len(str)`
|
(4)如何获取一个字符串的字节数:`len(str)`
|
||||||
|
|
||||||
如何获取一个字符串的字符数:
|
如何获取一个字符串的字符数:
|
||||||
|
|
||||||
最快速:`utf8.RuneCountInString(str)`
|
最快速:`utf8.RuneCountInString(str)`
|
||||||
|
|
||||||
`len([]int(str)) //TBD`
|
`len([]int(str)) //TBD`
|
||||||
|
|
||||||
(5)如何连接字符串:
|
(5)如何连接字符串:
|
||||||
最快速: `with a bytes.Buffer`(参考[章节7.2](7.2.md))
|
|
||||||
|
|
||||||
`Strings.Join()`(参考[章节4.7](4.7.md))
|
最快速: `with a bytes.Buffer`(参考[章节7.2](07.2.md))
|
||||||
|
|
||||||
|
`Strings.Join()`(参考[章节4.7](04.7.md))
|
||||||
|
|
||||||
`+=`
|
`+=`
|
||||||
|
|
||||||
@@ -47,12 +50,12 @@ for ix, ch := range str {
|
|||||||
str1 += str2 //str1 == "Hello World!"
|
str1 += str2 //str1 == "Hello World!"
|
||||||
```
|
```
|
||||||
|
|
||||||
(6)如何解析命令行参数:使用os或者flag包
|
(6)如何解析命令行参数:使用`os`或者`flag`包
|
||||||
|
|
||||||
(参考[例12.4](examples/chapter_12/fileinput.go))
|
(参考[例12.4](examples/chapter_12/fileinput.go))
|
||||||
|
|
||||||
## 链接
|
## 链接
|
||||||
|
|
||||||
- [目录](directory.md)
|
- [目录](directory.md)
|
||||||
- 上一节:[出于性能考虑的实用代码片段](18.0.md)
|
- 上一章:[出于性能考虑的实用代码片段](18.0.md)
|
||||||
- 下一节:[数组和切片](18.2.md)
|
- 下一节:[数组和切片](18.2.md)
|
||||||
Reference in New Issue
Block a user