代码拉取完成,页面将自动刷新
package StringHelper
import "errors"
/*
*
字符串截取
*/
func SubStr(str string, start int, end int) (string, error) {
if len(str) == 0 {
return str, nil
}
//if start > end {
// return "", errors.New("end max be than start")
//}
if start > end && end > 0 {
return "", errors.New("end max be than start")
}
//当start >-1 且end小于,则以start 开始
if start > -1 && end < 1 {
return str[start:], nil
} else if start > -1 && end > 0 && end > start {
//当start 大一-1 且 end大于0 且end>start
return str[start:end], nil
} else if start < 0 && end > 0 {
strLen := len(str)
if strLen <= end {
return str, nil
}
st := strLen - end
return str[st:], nil
} else {
return "", errors.New("un normal intercept parameter")
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。