File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change
1
+ # 第二章 文本 #
2
+
3
+ 几乎任何程序都离不开文本(字符串)。Go 中 string 是内置类型,同时它与普通的 slice 类型有着相似的性质,例如,可以进行切片(slice)操作,这使得 Go 中少了一些处理 string 类型的函数,比如没有 substring 这样的函数,然而却能够很方便的进行这样的操作。除此之外,Go 标准库中有几个包专门用于处理文本。
4
+
5
+ * strings* 包提供了很多操作字符串的简单函数,通常一般的字符串操作需求都可以在这个包中找到。
6
+
7
+ * strconv* 包提供了基本数据类型和字符串之间的转换。在 Go 中,没有隐式类型转换,一般的类型转换可以这么做:int32(i),将 i (比如为 int 类型)转换为 int32,然而,字符串类型和 int、float、bool 等类型之间的转换却没有这么简单。
8
+
9
+ 进行复杂的文本处理必然离不开正则表达式。* regexp* 包提供了正则表达式功能,它的语法基于 [ RE2] ( http://code.google.com/p/re2/wiki/Syntax ) ,* regexp/syntax* 子包进行正则表达式解析。
10
+
11
+ Go 代码使用 UTF-8 编码(且不能带 BOM),同时标识符支持 Unicode 字符。在标准库 * unicode* 包及其子包 utf8、utf16中,提供了对 Unicode 相关编码、解码的支持,同时提供了测试 Unicode 码点(Unicode code points)属性的功能。
12
+
13
+ 在开发过程中,可能涉及到字符集的转换,作为补充,本章最后会讲解一个第三方库:mahonia — 纯 Go 语言实现的字符集转换库,以方便需要进行字符集转换的读者。
14
+
15
+ # 导航 #
16
+
17
+ - [ 第一章] ( /chapter01/01.0.md )
18
+ - 下一节:[ strings — 字符串操作] ( 02.1.md )
Original file line number Diff line number Diff line change
1
+ # 2.1 strings — 字符串操作 #
2
+
3
+
4
+
5
+ # 导航 #
6
+
7
+ - [ 第一章] ( /chapter01/01.0.md )
8
+ - 下一节:[ strconv — 基本数据类型和字符串之间转换] ( 02.2.md )
Original file line number Diff line number Diff line change 4
4
- 1.3. [ fmt — 格式化IO] ( chapter01/01.3.md )
5
5
- 1.4. [ bufio — 缓存IO] ( chapter01/01.4.md )
6
6
* [ 第二章 文本] ( chapter02/02.0.md )
7
- - 2.1. strings — 字符串操作
8
- - 2.2 strconv — 基本类型和字符串之间转换
9
- - 2.3 regexp — 正则表达式
10
- - 2.4 unicode — Unicode码点、UTF-8/16编码
7
+ - 2.1. [ strings — 字符串操作] ( chapter02/02.1.md )
8
+ - 2.2. strconv — 基本数据类型和字符串之间转换
9
+ - 2.3. regexp — 正则表达式
10
+ - 2.4. unicode — Unicode码点、UTF-8/16编码
11
11
* 第三章 数据结构与算法
12
12
- 3.1 container — 容器数据类型:heap、list和ring
13
13
- 3.2 bytes — byte slice 便利操作
You can’t perform that action at this time.
0 commit comments