The StartsWith() Method is used to check, if a String begins with a particular substring.
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");
}
}
}
In the above code, we have declared a String Hello Beautiful World and assigned it to a variable x.
string x = "Hello Beautiful World";
-Method1.png)
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.