strings.LastIndex() Function in Golang With Examples Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report strings.LastIndex() function in the Golang returns the starting index of the occurrence of the last instance of a substring in a given string. If the substring is not found then it returns -1. Thus, this function returns an integer value. The index is counted taking zero as the starting index of the string. Syntax: func LastIndex(str, substring string) int Here, str is the original string and substring is a string, whose we want to find the last index value. Example 1: C // Golang program to illustrate the // strings.LastIndex() Function package main import ( "fmt" "strings" ) func main() { // taking a string str := "GeeksforGeeks" substr := "Geeks" fmt.Println(strings.LastIndex(str, substr)) } Output: 8 The string is "GeeksforGeeks" and the substring is "Geeks" so the compiler finds the substring present in the original string and displays the starting index of the last instance of substring which is 8. Example 2: C // Golang program to illustrate the // strings.LastIndex() Function package main import ( "fmt" "strings" ) func main() { // taking strings str := "My favorite sport is football" substr1 := "f" substr2 := "ll" substr3 := "SPORT" // using the function fmt.Println(strings.LastIndex(str, substr1)) fmt.Println(strings.LastIndex(str, substr2)) fmt.Println(strings.LastIndex(str, substr3)) } Output: 21 27 -1 The string is "My favorite sport is football" and the substrings are "f", "ll" and "SPORT" so the compiler displays the output as 21 and 27 in the first two cases respectively and since the third substring is "SPORT" which is considered as not present in the string as the function is case sensitive so it will give the result as -1. Comment More infoAdvertise with us Next Article strings.IndexAny() Function in Golang With Examples P prakhar7 Follow Improve Article Tags : Go Language Golang-String Similar Reads strings.LastIndexAny() Function in Golang With Examples strings.LastIndexAny() Function in the Golang is used to find the index of the last instance of any Unicode code point from chars in a given string. If the Unicode code point from chars is not found then it returns -1. Thus, this function returns an integer value. The index is counted taking zero as 2 min read strings.LastIndexByte() Function in Golang With Examples strings.LastIndexByte() Function in Golang returns the index of the last instance of the given byte in the original string. If the given byte is not available in the original string, then this method will return -1. Syntax: func LastIndexByte(str string, b byte) int Here, str is the original string 1 min read strings.LastIndexFunc() Function in Golang With Examples strings.LastIndexFunc() Function in Golang returns the index of string s of the last Unicode code point, which satisfies func(c), or it returns -1 if no matches found. Syntax: func LastIndexFunc(s string, f func(rune) bool) int Here, s is the string and func() is a function. Return Value: It returns 1 min read strings.Index() Function in Golang With Examples strings.Index() Function in Golang is used to get the first instance of a specified substring. If the substring is not found, then this method will return -1. Syntax: func Index(str, sbstr string) int Here, str is the original string and sbstr is a string whose we want to find index value. Example 1 2 min read strings.IndexAny() Function in Golang With Examples strings.IndexAny() Function in Golang is used to returns the index of the first instance of any Unicode code point from chars in the original string. If the Unicode code point from chars is not available in the original string, then this method will return -1. Syntax: func IndexAny(str, charstr stri 2 min read strings.IndexByte() Function in Golang With Examples strings.IndexByte() Function in Golang returns the index of the first instance of the given byte in the original string. If the given byte is not available in the original string, then this method will return -1. Syntax: func IndexByte(str string, b byte) int Here, str is the original string and b i 1 min read Like