golang 截取字符串
程序员文章站
2022-05-29 22:22:04
...
package main
import (
"fmt"
)
func ttrim(dat []byte) []byte {
flag := false
start := 0
end := 0
for i, v := range dat {
if (v >= 0 && v <= 9) || (v >= '0' && v <= '9') || (v >= 'a' && v <= 'z') || (v >= 'A' && v <= 'Z') {
if flag == false {
start = i
end = i
flag = true
} else {
end = i
}
} else {
if flag == true {
fmt.Println("start ,end =", start, end)
end = i
break
}
}
}
return dat[start:end]
}
func main() {
fmt.Println("vim-go")
str := "*?>?,.,.,.?>>a123kjdslrd90jcd09er0jejj9*,=_---->>>....,l+"
ss := ttrim([]byte(str))
fmt.Println(str)
fmt.Println(string(ss))
}
下一篇: golang 使用protobuf