// SplitAny:split by any char
func SplitAny(str string, sep string) []string {
result := make([]string,0)
iLast := 0
iStrLen:= len(str)
for {
//find Start
iStart:=-1
for i:=iLast;i<iStrLen;i++ {
if strings.IndexByte(sep,str[i]) ==-1{
iStart =i
break
}
}
if iStart ==-1{
break
}
//find end
iEnd:=-1
for i:=iStart+1;i<iStrLen;i++ {
if strings.IndexByte(sep,str[i]) !=-1{
iEnd =i
iLast=i+1
break
}
}
if iEnd ==-1{
iEnd = iStrLen
iLast =iEnd
}
result = append(result,str[iStart:iEnd])
}
return result
}
实现Split函数
最新推荐文章于 2021-06-29 20:19:46 发布