strings.ContainsRune() Function in Golang with Examples
The Unicode, which is a superset of ASCII and contains all the characters present in the world’s writing system, is the character set that’s being followed right now. Each character in the Unicode system is uniquely identified by a Unicode code point, which is referred to as runes in Golang. To know more about runes please go through the article Runes in Golang
strings.ContainsRune() Function in Golang is used to check the given string contains the specified rune or not in it.
Syntax:
func ContainsRune(s string, r rune) bool
Here, str is the string and r is s rune.
It returns a boolean value true if the character specified by the rune is present in the string, else false.
Example 1:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ContainsRune( "geeksforgeeks" , 97))
}
|
Output:
false
The above code returns false as the character specified by the rune, or Unicode code point, 97, which is ‘a’, is not present in the string that is passed, “geeksforgeeks”.
Example 2:
package main
import (
"fmt"
"strings"
)
func main() {
str := "geeksforgeeks"
if strings.ContainsRune(str, 103) {
fmt.Println( "Yes" )
} else {
fmt.Println( "No" )
}
}
|
Output:
Yes
Last Updated :
19 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...