String StartsWith and EndsWith in C# – String Method C#



String StartsWith() and EndsWith() Method in C#

StratsWith() – The C# StartsWith() string method check if the parameter string start with specified string.

EndsWith() – The C#  EndsWith() string method check if the parameter string end with specified string.

The StartsWith() and EndsWith() return bool value true / false in output.

C# Example of String StartsWith()

meeraacademy.com
String StartsWith() Example in C#

C# code for above StartsWith() example :

protected void Button1_Click(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;

Label1.Text = str1.StartsWith(str2).ToString();
}

C# Example of String EndsWith()

meeraacademy.com
String EndsWith() Example in C#

C# code for above EndsWith() example :

protected void Button2_Click(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;

Label1.Text = str1.EndsWith(str2).ToString();
}

Subscribe us

If you liked this c#.net post, then please subscribe to our YouTube Channel for more c#.net video tutorials.

We hope that this C#.net tutorial helped you to understand String StartsWith() and EndsWith() Method.


Next asp.net tutorial we will learn about C# String Length Function.

Leave a Reply

Your email address will not be published. Required fields are marked *