Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   






ContainsAny() FUNCTION


ContainsAny() Function


The ContainsAny() Function returns true, if any 1 letter of the searched substring matches.


Let us clear with the below example


Example :



package main
import "fmt"
import "strings"
    
func main() {
    
    x := "Beautiful"
    y := strings.ContainsAny(x, "tp")
            
    if (y == true) { 
        fmt.Println("Any one of the letter 't' or 'p' is present in the String")  
    } else {
        fmt.Println("None of the letter 't' or 'p' is present in the String")
    }	 	
}


Output :



 Any one of the letter 't' or 'p' is present in the String

In the above code, we have declared a String 'Beautiful' and assigned it to a variable 'x'.


x := "Beautiful"

java_Collections

And we would be searching if any 1 letter, either 't' or 'p' is present in the String "Beautiful".


y := strings.ContainsAny(x, "tp")

And we can see that the letter 't' is present in the String "Beautiful".


java_Collections

And the below output is printed.


Any one of the letter 't' or 'p' is present in the String