Skip to content
Related Articles

Related Articles

strings.ContainsRune() Function in Golang with Examples
  • Last Updated : 19 Apr, 2020

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
Recommended Articles
Page :