In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
In the Go strings, you can also find the first index of the specified rune in the given string using IndexRune() function. This function returns the index of the first instance of the Unicode code point, i.e, specified rune, or -1 if the specified rune is not present in the given string. If the rune is utf8.RuneError, then it returns the first instance of any invalid UTF-8 byte sequence. It is defined under the string package so, you have to import string package in your program for accessing IndexRune function.
func IndexRune(str string, r rune) int
Index Value 1: -1 Index Value 2: 3 Index Value 3: 0
String 1: Welcome to GeeksforGeeks , Rune 1:'R' , Index Value: -1 String 2: AppleAppleAppleAppleAppleApple , Rune 2:'l' , Index Value: 3 String 3: %G%E%E%K%S , Rune 3:'*' , Index Value: -1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.