Golang | How to find the index of rune in the string? Last Updated : 28 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: func IndexRune(str string, r rune) int Example 1: C // Go program to illustrate how to find // the index value of the given rune package main import ( "fmt" "strings" ) func main() { // Creating and Finding the first index // of the rune in the given string // Using IndexRunefunction res1 := strings.IndexRune("****Welcome to GeeksforGeeks****", 60) res2 := strings.IndexRune("Learning how to trim"+ " a slice of bytes", 'r') res3 := strings.IndexRune("GeeksforGeeks", 'G') // Display the results fmt.Println("Index Value 1: ", res1) fmt.Println("Index Value 2: ", res2) fmt.Println("Index Value 3: ", res3) } Output: Index Value 1: -1 Index Value 2: 3 Index Value 3: 0 Example 2: C // Go program to illustrate how to find // the index value of the given rune package main import ( "fmt" "strings" ) func main() { // Creating and initializing a string // Using shorthand declaration string_1 := "Welcome to GeeksforGeeks" string_2 := "AppleAppleAppleAppleAppleApple" string_3 := "%G%E%E%K%S" // Creating and initializing rune var r1, r2, r3 rune r1 = 'R' r2 = 'l' r3 = 42 // Finding the first index // of the given rune // Using IndexRune function res1 := strings.IndexRune(string_1, r1) res2 := strings.IndexRune(string_2, r2) res3 := strings.IndexRune(string_3, r3) // Display the results fmt.Printf("String 1: %s , Rune 1:%q , Index Value: %d", string_1, r1, res1) fmt.Printf("\nString 2: %s , Rune 2:%q , Index Value: %d", string_2, r2, res2) fmt.Printf("\nString 3: %s , Rune 3:%q , Index Value: %d", string_3, r3, res3) } Output: 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 Comment More infoAdvertise with us A ankita_saini Follow Improve Article Tags : Go Language Golang Golang-String Similar Reads Go Tutorial Go or you say Golang is a procedural and statically typed programming language having the syntax similar to C programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language and mainly used in Google 2 min read Go Programming Language (Introduction) Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports env 11 min read time.Sleep() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Sleep() function in Go language is used to stop the latest go-routine for at least the stated duration d. And a negative or zero duration of sleep will cause this method to return instantly. Moreover, t 3 min read Golang Tutorial - Learn Go Programming Language This Golang tutorial provides you with all the insights into Go Language programming, Here we provide the basics, from how to install Golang to advanced concepts of Go programming with stable examples. So, if you are a professional and a beginner, this free Golang tutorial is the best place for your 10 min read Top 10 Golang Project Ideas with Source Code in 2025 Golang, or Go, a programming language was created by Google. It's widely used for building different kinds of applications like websites and cloud services. The fastest way to master this language is by building projects related to it. This article introduces 10 beginner-friendly to medium-difficult 8 min read Interfaces in Golang In Go, an interface is a type that lists methods without providing their code. You canât create an instance of an interface directly, but you can make a variable of the interface type to store any value that has the needed methods.Exampletype Shape interface { Area() float64 Perimeter() float64}In t 3 min read Top 10 Golang Frameworks in 2025 Golang (or Go) is an open-source compiled programming language that is used to build simple, systematic, and secure software. It was designed by Google in the year 2007 and has been readily adopted by developers all over the world due to its features like memory safety, structural typing, garbage co 9 min read strings.Contains Function in Golang with Examples strings.Contains Function in Golang is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false. Syntax:Â func Contains(str, substr string) bool Here, str is the original string and substr is t 2 min read fmt.Sprintf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintf() function in Go language formats according to a format specifier and returns the resulting string. Moreover, this function is defined under the fmt package. Here, you 2 min read Data Types in Go Data types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows: Basic type: Numbers, strings, and booleans come under this category.Aggregate type: Array and structs come under this category.Reference type: Pointer 7 min read Like