e := strings.Index(result, "Country") //Searching for the country info like Country: US
当我得到索引时,我会搜索我需要下一个单词之类的信息。这就是我要找的。任何想法以最佳方式解决此问题?
心有法竹
浏览 208回答 3
3回答
蝴蝶不菲
这是另一种查找字符串索引的方法。按该字符串拆分,然后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