x := "a_ab_daqe_sd_ew"
lastInd := strings.LastIndex(x, "_")
fmt.Println(x[:lastInd]) // a_ab_daqe_sd
fmt.Println(x[lastInd+1:]) // ew
根据最后一个标识截取前面或者后面的字符串
最新推荐文章于 2022-04-13 15:43:05 发布
x := "a_ab_daqe_sd_ew"
lastInd := strings.LastIndex(x, "_")
fmt.Println(x[:lastInd]) // a_ab_daqe_sd
fmt.Println(x[lastInd+1:]) // ew