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




StartsWith() - Method


StartsWith() Method


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


Example :



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


Output :



  The String starts with Hello

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 starts with the substring Hello.


if (x.StartsWith("Hello"))
{
	System.Console.WriteLine("The String starts with Hello");
}
else
{
	System.Console.WriteLine("The String does not start with Hello");
}

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


And thus we get the below output.

Output :



  The String starts with Hello