IsOneOf() functionThe IsOneOf() function is a built-in function of the Unicode package that determines whether the given rune r belongs to one of the specified range tables.
func IsOneOf(ranges []*RangeTable, r rune) bool
ranges: A table with one or more ranges.
r: The rune type value we want to see if it is a member of one of the ranges.
The Unicode.IsOneOf() function returns true if rune r is a member of one of the ranges. Otherwise, it returns false.
Note: We must import the Unicode package into our program to use the
IsOneOf()function.
package main
  
import (
    "fmt"
    "unicode"
)
The following code shows how to use the Unicode.IsOneOf() function in Golang.
// Golang program// Using unicode.IsOneOf() Functionpackage mainimport ("fmt""unicode")func main() {// declare rangeTable// contains letter and digitsvar letterDigit = []*unicode.RangeTable{unicode.Letter,unicode.Digit,{R16: []unicode.Range16{{'_', '_', 1}}},}// declaring a constant str with type runesconst str = "Edu5Ὂca?tive@~Shot℃ᾭ&*"// checks each character whether it is within the rangeTable// result is displayed based on the return valuefor _, i := range str {if unicode.IsOneOf(letterDigit, i) == true {fmt.Printf("%c is in the range\n", i)} else {fmt.Printf("%c is not the range\n",i)}}}
The following is another code example that checks if each character is in the string (rune type).
// Golang program// Using unicode.IsOneOf() Functionpackage mainimport ("fmt""unicode")func main() {// declare rangeTable// contains letter and digitsvar letterDigit = []*unicode.RangeTable{unicode.Letter,unicode.Digit,{R16: []unicode.Range16{{'_', '_', 1}}},}// declaring a constant str with type runesconst str = "Edu5Ὂca?tive@~Shot℃ᾭ&*"// checks each character whether it is within the rangeTable// result is displayed based on the return valuefor _, i := range str {if unicode.IsOneOf(letterDigit, i) == true {fmt.Printf("%c is in the range\n", i)} else {fmt.Printf("%c is not the range\n",i)}}}