From 50565c97656e94b3f6d0aea3c3830ab1b4d24164 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 19 Aug 2020 22:34:54 +0800 Subject: [PATCH] update doc --- doc/keywords.md | 15 +++++++++++---- example/stringx/replace/replace.go | 7 ++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/keywords.md b/doc/keywords.md index a1748522..fd9ee05d 100644 --- a/doc/keywords.md +++ b/doc/keywords.md @@ -10,23 +10,28 @@ ## 2. 关键词替换 +支持关键词重叠,自动选用最长的关键词,代码示例如下: + ```go replacer := stringx.NewReplacer(map[string]string{ - "PHP": "PPT", - "世界上": "吹牛", + "日本": "法国", + "日本的首都": "东京", + "东京": "日本的首都", }) -fmt.Println(replacer.Replace("PHP是世界上最好的语言!")) +fmt.Println(replacer.Replace("日本的首都是东京")) ``` 可以得到: ``` -PPT是吹牛最好的语言! +东京是日本的首都 ``` 示例代码见`example/stringx/replace/replace.go` ## 3. 查找敏感词 +代码示例如下: + ```go filter := stringx.NewTrie([]string{ "AV演员", @@ -47,6 +52,8 @@ fmt.Println(keywords) ## 4. 敏感词过滤 +代码示例如下: + ```go filter := stringx.NewTrie([]string{ "AV演员", diff --git a/example/stringx/replace/replace.go b/example/stringx/replace/replace.go index 4c6961c7..582890d9 100644 --- a/example/stringx/replace/replace.go +++ b/example/stringx/replace/replace.go @@ -8,8 +8,9 @@ import ( func main() { replacer := stringx.NewReplacer(map[string]string{ - "PHP": "PPT", - "世界上": "吹牛", + "日本": "法国", + "日本的首都": "东京", + "东京": "日本的首都", }) - fmt.Println(replacer.Replace("PHP是世界上最好的语言!")) + fmt.Println(replacer.Replace("日本的首都是东京")) }