这是查找字符串索引的另一种方法。按该字符串拆分,然后length of the first index是该字符串第一次出现的索引。https://play.golang.org/p/x7QWyuC_1wK result := "City:San Fran,State:CA,Country:US" // split the string s := strings.Split(result, "US") // index of US index := len(s[0]) fmt.Println(index)// Output U 31