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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the
// strings.ContainsRune() Function
package main
  
import (
    "fmt"
    "strings"
)
  
func main() {
  
    // using the function
    fmt.Println(strings.ContainsRune("geeksforgeeks", 97))
}

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the
// strings.ContainsRune() Function
package main
  
import (
    "fmt"
    "strings"
)
  
func main() {
    str := "geeksforgeeks"
  
    // using the function
    if strings.ContainsRune(str, 103) {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}

chevron_right


Output:

Yes



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.