Menu Close

Go – How to check if Unicode code point or rune is present in string ?

Here, We are going to learn about checking unicode point or rune is present in string.We can check this by using ContainsRune() function of strings package in go golang.

Function prototype:

func ContainsRune(str string, r rune) bool

Return value:

ContainsRune() function returns whether the Unicode code point r is within str as true and false value respectively.

Example:

package main

import (
	"fmt"
	"strings"
)

func main() {
	// Finds whether a string contains a particular Unicode code
	// point.
	
	// The code point for the lowercase letter "a", for example,
	// is 97.
	
	fmt.Println(strings.ContainsRune("aadlik", 97))
	
	fmt.Println(strings.ContainsRune("peek", 97))
	
}

Output:

true
false

To learn more about golang, Please refer given below link.

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
https://golang.org/pkg/strings/
Posted in golang, packages, strings

Leave a Reply

Your email address will not be published.

Contact Us