update doc
This commit is contained in:
@@ -10,23 +10,28 @@
|
|||||||
|
|
||||||
## 2. 关键词替换
|
## 2. 关键词替换
|
||||||
|
|
||||||
|
支持关键词重叠,自动选用最长的关键词,代码示例如下:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
replacer := stringx.NewReplacer(map[string]string{
|
replacer := stringx.NewReplacer(map[string]string{
|
||||||
"PHP": "PPT",
|
"日本": "法国",
|
||||||
"世界上": "吹牛",
|
"日本的首都": "东京",
|
||||||
|
"东京": "日本的首都",
|
||||||
})
|
})
|
||||||
fmt.Println(replacer.Replace("PHP是世界上最好的语言!"))
|
fmt.Println(replacer.Replace("日本的首都是东京"))
|
||||||
```
|
```
|
||||||
|
|
||||||
可以得到:
|
可以得到:
|
||||||
```
|
```
|
||||||
PPT是吹牛最好的语言!
|
东京是日本的首都
|
||||||
```
|
```
|
||||||
|
|
||||||
示例代码见`example/stringx/replace/replace.go`
|
示例代码见`example/stringx/replace/replace.go`
|
||||||
|
|
||||||
## 3. 查找敏感词
|
## 3. 查找敏感词
|
||||||
|
|
||||||
|
代码示例如下:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
filter := stringx.NewTrie([]string{
|
filter := stringx.NewTrie([]string{
|
||||||
"AV演员",
|
"AV演员",
|
||||||
@@ -47,6 +52,8 @@ fmt.Println(keywords)
|
|||||||
|
|
||||||
## 4. 敏感词过滤
|
## 4. 敏感词过滤
|
||||||
|
|
||||||
|
代码示例如下:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
filter := stringx.NewTrie([]string{
|
filter := stringx.NewTrie([]string{
|
||||||
"AV演员",
|
"AV演员",
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
replacer := stringx.NewReplacer(map[string]string{
|
replacer := stringx.NewReplacer(map[string]string{
|
||||||
"PHP": "PPT",
|
"日本": "法国",
|
||||||
"世界上": "吹牛",
|
"日本的首都": "东京",
|
||||||
|
"东京": "日本的首都",
|
||||||
})
|
})
|
||||||
fmt.Println(replacer.Replace("PHP是世界上最好的语言!"))
|
fmt.Println(replacer.Replace("日本的首都是东京"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user