strings.ContainsAny() Function in Golang with Examples
Last Updated :
08 Jun, 2020
ContainsAny function is used to check whether any Unicode code points in chars are present in the string. It is an inbuilt function used to find if a specified string exists in the string if found it will return true or else false.
Syntax:
func ContainsAny(str, charstr string) bool
Here, the first parameter is the original string and the second parameter is the substring or a set of characters which is to be found within the string. Even if one of the characters in the substring is found in the string, the function returns true. The function returns a boolean value i.e. true/false depending on the input.
Example:
package main
import (
"fmt"
"strings"
)
func main() {
str1 := "Welcome to Geeks for Geeks"
str2 := "We are here to learn about go strings"
res1 := strings.ContainsAny(str1, "Geeks" )
res2 := strings.ContainsAny(str2, "GFG" )
res3 := strings.ContainsAny( "GeeksforGeeks" , "Gz" )
res4 := strings.ContainsAny( "GeeksforGeeks" , "ue" )
res5 := strings.ContainsAny( "GeeksforGeeks" , " " )
fmt.Println( "\nResult 1: " , res1)
fmt.Println( "Result 2: " , res2)
fmt.Println( "Result 3: " , res3)
fmt.Println( "Result 4: " , res4)
fmt.Println( "Result 5: " , res5)
}
|
Output:
Result 1: true
Result 2: false
Result 3: true
Result 4: true
Result 5: false
Share your thoughts in the comments
Please Login to comment...