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:
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 return 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' "
|