strings.Index() Function in Golang With Examples Last Updated : 19 Apr, 2020 Comments Improve Suggest changes Like Article Like Report 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: C // Go program to illustrate the // String Index() Function package main import ( "fmt" "strings" ) // Main function func main() { // Creating and initializing the strings str1 := "Welcome to GeeksforGeeks" str2 := "My name is XYZ" // Displaying strings fmt.Println("String 1: ", str1) fmt.Println("String 2: ", str2) // Using Index() function res1 := strings.Index(str1, "Geeks") res2 := strings.Index(str2, "is") // Displaying the result fmt.Println("\nIndex values:") fmt.Println("Result 1: ", res1) fmt.Println("Result 2: ", res2) } Output: String 1: Welcome to GeeksforGeeks String 2: My name is XYZ Index values: Result 1: 11 Result 2: 8 Example 2: C // Go program to illustrate the // String Index() Function package main import ( "fmt" "strings" ) // Main function func main() { // Using Index() function res1 := strings.Index("GFG", "H") res2 := strings.Index("GeeksforGeeks", "for") // Displaying the result fmt.Println("Result 1: ", res1) fmt.Println("Result 2: ", res2) } Output: Result 1: -1 Result 2: 5 Comment More infoAdvertise with us Next Article strings.Index() Function in Golang With Examples K Kirti_Mangal Follow Improve Article Tags : Go Language Golang-String Similar Reads 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 strings.IndexFunc() Function in Golang With Examples strings.IndexFunc() Function in Golang is used to returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do. Syntax: func IndexFunc(str string, f func(rune) bool) int Here, str is string which may contain Unicode code point and f is func which validates the Unicode p 1 min read strings.LastIndex() Function in Golang With Examples 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 2 min read strings.IndexRune() Function in Golang With Examples strings.IndexRune() Function in Golang is used to find the first index of the specified rune in the given string. It is defined under the string package so, you have to import string package in your program for accessing IndexRune function Syntax: func IndexRune(str string, r rune) int This function 2 min read strings.Join() Function in Golang With Examples strings.Join() Function in Golang concatenates all the elements present in the slice of string into a single string. This function is available in the string package. Syntax: func Join(s []string, sep string) string Here, s is the string from which we can concatenate elements and sep is the separato 1 min read 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.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.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.SplitN() Function in Golang with Examples strings.SplitN() Function() is a string manipulation function in Go language. It is used to split a given string into substrings separated by a separator. This function returns the slices of all substrings between those separators. Syntax: func SplitN(s, sep string, n int) []string Here, s is the st 3 min read Like