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.
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 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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer