Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

How to use C# string EndsWith



EndsWith in C# string Class check if the Parameter String EndsWith the Specified String.

bool string.EndsWith(string suffix)

Parameters:

  • the suffix – The passing String for it EndsWith.

Returns:

  • Boolean – Yes/No.

If the String EndsWith the Parameter String it returns True

If the String doesn’t EndsWith the Parameter String, it returns False

For ex: “This is a Test”.EndsWith(“Test”) returns True

“This is a Test”.EndsWith(“is”) returns False

Exceptions:

  • System.ArgumentNullException: If the argument is null
using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			string str = null;
			str = "VB.NET TOP 10 BOOKS";
			if (str.EndsWith("BOOKS") == true)
			{
				MessageBox.Show("The String EndsWith 'BOOKS' ");
			}
			else
			{
				MessageBox.Show("The String does not EndsWith 'BOOKS'");
			} 
		}
	}
}

When you execute the C# program, you will get a message box like “The String EndsWith ‘BOOKS’.


Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More