The Contains() Function is used to find a substring from the String.
package main import "fmt" import "strings" func main() { x := "Beautiful" y := strings.Contains(x, "tif") if (y == true) { fmt.Println("The substring tif is present in the String") } else { fmt.Println("The substring tif is not present in the String") } }
In the above code, we have declared a String 'Beautiful' and assigned it to a variable 'x'.
And we would be searching the substring 'tif', from the String, 'Beautiful'.
So, we have used the 'Contains()' Function to find if the substring 'tif' is present in the String, 'Beautiful'.
And what 'Contains()' Function does is, goes to the String 'Beautiful' and searches if the substring 'tif' is present in it or not.
And finds the substring substring 'tif' is present.
And the below output is printed.