golang零宽度字符检测与移除插件库go-zero-width的使用
golang零宽度字符检测与移除插件库go-zero-width的使用
简介
go-zero-width 是一个用于检测和移除零宽度字符的 Go 语言库。该库灵感来源于一篇关于零宽度字符的文章。
安装
go get github.com/trubitsyn/go-zero-width
使用示例
package main
import (
"github.com/trubitsyn/go-zero-width"
"fmt"
)
func main() {
// 字符串中包含零宽度空格(在"c"和"d"之间)
login := "abcdef"
// 移除零宽度字符
clean := zerowidth.RemoveZeroWidthCharacters(login)
// 打印原始字符串的十六进制表示(包含零宽度字符 e2 80 8b)
fmt.Printf("% x\n", login) // 输出: 61 62 63 e2 80 8b 64 65 66
// 打印清理后的字符串的十六进制表示
fmt.Printf("% x\n", clean) // 输出: 61 62 63 64 65 66
}
支持的零宽度字符
- 零宽度空格 (U+200B)
- 零宽度非断空格 (U+FEFF)
- 零宽度连接符 (U+200D)
- 零宽度非连接符 (U+200C)
测试
go get -t github.com/trubitsyn/go-zero-width
go test github.com/trubitsyn/go-zero-width
许可证
Copyright 2018 Nikola Trubitsyn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
更多关于golang零宽度字符检测与移除插件库go-zero-width的使用的实战教程也可以访问 https://www.itying.com/category-94-b0.html
1 回复