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,12 @@
|
||||
package stringx
|
||||
|
||||
// DeleteElement 删除切片中指定下标的元素(泛型,支持任意切片类型)
|
||||
func DeleteElement[S []T, T any](slice S, index int) S {
|
||||
if index < 0 || index >= len(slice) {
|
||||
return slice
|
||||
}
|
||||
// 计算要删除的元素后面的元素需要向前移动多少位置
|
||||
n := len(slice) - 1
|
||||
copy(slice[index:n], slice[index+1:n+1])
|
||||
return slice[:n]
|
||||
}
|
||||
Reference in New Issue
Block a user