Return last item of strings.Split() slice in Golang
strings.LastIndex makes this quite neat: s := “Hello,Stack,Overflow” last := s[strings.LastIndex(s, “,”)+1:] fmt.Println(last) returns “Overflow”. If the search string isn’t found it returns the whole string, which is logical. Playground here