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






HasSuffix() FUNCTION


HasSuffix() Function


The HasSuffix() Function is used to check if a String edns with a given set of Characters.


Example :



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")
    }		
}	


Output :



 The String ends with the sub string lo

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


x := "Hello"

java_Collections

And we would be checking if the String 'Hello' ends with 'lo'.


So, we have used the 'HasSuffix()' Function to check.


y := strings.HasSuffix(x, "lo")

And what 'HasPrefix()' Function does is, goes to the String 'Hello Beautiful World' and searches if the String ends with 'lo'.


java_Collections

And finds that the String 'Hello' begins with 'lo'.


So the control gets into the 'if' block and the below output is printed.


The String ends with the sub string lo