I need to take a string in this format 1704 Woodward Avenue, Muscle Shoals and take the substring after the ', ' and compare it with another string. I keep trying to use the strings.Split(data,', ') but it keeps erroring after I do it. Can anyone point me in the right direction for getting subStrings and making comparison in Golang?
Code:
for i := 0; i < len(results.Results); i++ {
datatest := values[i].Name
dtresult := strings.Split(datatest, ", ")
if dtresult[1] == ps.ByName("name") {
values[i].Name = results.Results[i].Name
values[i].Rating = strconv.FormatFloat(results.Results[i].Rating, 'f', 1, 64)
values[i].Icon = results.Results[i].Icon
values[i].Address = results.Results[i].Address
}
}
Error: 2019/02/16 23:34:22 http: panic serving [::1]:51632: runtime error: index out of range goroutine 19 [running]:
Thanks