函数原型

func substr(s1 string, start int, length int) string

参数介绍

参数名称参数介绍
s1需要被分割的字符串
start开始分割的位置
length分割长度

举例

待转换数据转换语句输出结果
abcdefgsubstr("abcdefg", 1, 2)bc
abcdefgsubstr("abcdefg", 100, 2)""
abcdefgsubstr("abcdefg", 1, 6)bcdefg
abcdefgsubstr("abcdefg", 1, 8)bcdefg
abcdefgsubstr("abcdefg", -1, 100)Error: "invalid substr index"
abcdefgsubstr("abcdefg", 1, -100)Error: "invalid substr index"
abcdefgsubstr("abcdefg", 0, 0)Error: "invalid substr index"

Was this page helpful?