feat(stringx): 自 go-hua/common 迁入字符串/切片/拼音工具并独立成包
- common 的 string.go/array.go/pinyin.go 拆为 stringx 包(含随机串、GUID、 通配符匹配、校验规则、链式缓冲、驼峰转下划线、切片删元素、拼音首字母) - 附单元测试与 examples/stringx 可运行例程、包 README - go.mod 新增直接依赖 mozillazg/go-pinyin(go-hua 同版本锁 v0.20.0→实际解析 v0.21.0)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// stringx 包示例:字符串/切片工具(随机串、GUID、取中间串、驼峰转下划线、
|
||||
// 通配符匹配、校验、中文首字母、切片删元素)
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.zeroonesoft.cn/golib/zogo/stringx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 随机字符串 / GUID
|
||||
fmt.Println("随机字符串:", stringx.CreateRandomString(16))
|
||||
fmt.Println("纯数字随机:", stringx.CreateRandomStringInt(6))
|
||||
fmt.Println("GUID:", stringx.GetGUID())
|
||||
|
||||
// 字符串处理
|
||||
fmt.Println("取中间字符串:", stringx.GetBetweenStr("key=value&x=1", "key=", "&"))
|
||||
fmt.Println("驼峰转下划线:", stringx.Camel2Case("GetUserName"))
|
||||
fmt.Println("通配符匹配:", stringx.IsMatchGreed("hello.txt", "*.txt"))
|
||||
|
||||
// 校验
|
||||
fmt.Println("手机号 13812345678:", stringx.CheckMobile("13812345678"))
|
||||
fmt.Println("身份证 110101199001011234:", stringx.CheckIdCard("110101199001011234"))
|
||||
|
||||
// 中文拼音首字母
|
||||
fmt.Println("拼音首字母:", stringx.GetFirstLetter("中国"))
|
||||
|
||||
// 切片删除指定下标元素
|
||||
s := []int{1, 2, 3, 4, 5}
|
||||
s = stringx.DeleteElement(s, 2)
|
||||
fmt.Println("删除下标2后:", s)
|
||||
}
|
||||
Reference in New Issue
Block a user