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 are allowed to check the given string contain the specified rune in it using ContainsRune() function. This function returns true if the given string contains the specified rune in it, or this function returns false if the given string does not contain the specified rune. It is defined under the string package so, you have to import string package in your program for accessing ContainsRune function.
func ContainsRune(str string, r rune) bool
Here, str is the string and r is s rune. The return type of this function is bool. Let us discuss this concept with the help of the given examples:
String 1: Welcome to GeeksforGeeks , Rune 1: 'R' , Present or Not: false String 2: AppleAppleAppleAppleAppleApple , Rune 2: 'p' , Present or Not: true String 3: %G%E%E%K%S , Rune 3: '*' , Present or Not: false
Final Result: Result 1: false Result 2: true Result 3: true
- Check If the Rune is a Letter or not in Golang
- Check If the Rune is a Space Character or not in Golang
- Check If the Rune is a Lowercase Letter or not in Golang
- Check If the Rune is a Decimal Digit or not in Golang
- Check If the Rune is a Symbolic Character or not in Golang
- Check If the Rune is an Uppercase Letter or not in Golang
- Check If the Rune is a Unicode Punctuation Character or not in Golang
- Golang | How to find the index of rune in the string?
- Rune in Golang
- How to Map a Rune to the Specified Case in Golang?
- How to Map a Rune to Lowercase in Golang?
- How to Map a Rune to Uppercase in Golang?
- How to Map a Rune to Title Case in Golang?
- Check if the given characters is present in Golang String
- Check if the String ends with specified suffix in Golang
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.