C# String Ends With

In this article we will discuss about how to use Ends With operation in C#.
  • 4542

The EndsWith method returns true if a strings ends with a specified string. The following code snippet checks if a string ends with "C# Corner". 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string sentence = "Mahesh Chand is an author and founder of C# Corner";
            Console.WriteLine("Original String: {0}", sentence);
            string findString = "C# Corner";
            bool b = sentence.EndsWith(findString);
            Console.WriteLine("String ends with {0}: {1}", findString, b);
            Console.ReadLine();
        }
    }
}


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.