Golang program to check a specified string contains a Unicode code point

Here, we are going to learn how to check a specified string contains a Unicode code point in Golang (Go Language)?
Submitted by Nidhi, on March 18, 2021 [Last updated : March 03, 2023]

How to check a string contains a Unicode code point in Golang?

Problem Solution:

In this program, we will create some strings and then check specified string contains a Unicode code point using ContainsRune() function. The ContainsRune() function returns Boolean value to the calling function.

The Unicode code point for the uppercase letter "A" is 65.

Program/Source Code:

The source code to check a specified string contains a Unicode code point is given below. The given program is compiled and executed successfully.

Golang code to check a specified string contains a Unicode code point

// Golang program to check a specified string
// contains a Unicode code point.

package main

import "fmt"
import "strings"

func main() {
	str1 := "INDIA"
	str2 := "AUSTRALIA"
	str3 := "AMERICA"
	str4 := "CANADA"

	// The Unicode code point for the uppercase letter "A" is 65.
	fmt.Println(strings.ContainsRune(str1, 65))
	fmt.Println(strings.ContainsRune(str2, 66))
	fmt.Println(strings.ContainsRune(str3, 65))
	fmt.Println(strings.ContainsRune(str4, 65))
}

Output:

true
false
true
true

Explanation:

In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.

In the main() function, we created four string variables str1, str2, str3, str4. After that, we checked the specified Unicode code point in the specified string using ContainsRune() function. If a specified Unicode code point is contained within the specified string then the ContainsRune() function returns true otherwise it will return false.

Golang String Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.