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




EndsWith() - Method


EndsWith() Method


The EndsWith() Method is used to check, if a String ends with a particular substring.


Example :



public class MyApplication
{
    public static void Main(string[] args)
    {
        string x = "Hello Beautiful World";
        if (x.EndsWith("World"))
        {
        	System.Console.WriteLine("The String ends with World");
        }
        else
        {
        	System.Console.WriteLine("The String does not end with World");
        }  		 	
    }
}


Output :



  The String ends with World

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


string x = "Hello Beautiful World";
C_Sharp


And we have checked if the String, Hello Beautiful World ends with the substring World.


if (x.EndsWith("World"))
{
	System.Console.WriteLine("The String ends with World");
}
else
{
	System.Console.WriteLine("The String does not end with World");
}

And in this case the String, substring Hello Beautiful World ends with the substring World


And thus we get the below output.

Output :



  The String ends with World