The HasSuffix() Function is used to check if a String edns with a given set of Characters.
package main import "fmt" import "strings" func main() { x := "Hello" y := strings.HasSuffix(x, "lo") if (y == true) { fmt.Println("The String ends with the sub string lo") } else { fmt.Println("The String does not ends with the sub string lo") } }
In the above code, we have declared a String 'Hello' and assigned it to a variable 'x'.
And we would be checking if the String 'Hello' ends with 'lo'.
So, we have used the 'HasSuffix()' Function to check.
And what 'HasPrefix()' Function does is, goes to the String 'Hello Beautiful World' and searches if the String ends with 'lo'.
And finds that the String 'Hello' begins with 'lo'.
So the control gets into the 'if' block and the below output is printed.