Check whether string ends with given substring or not using String.EndsWith() in C#?

String.EndsWith() Method of String class in C#: Here, we will learn how to check whether a given string ends with given string or not in C#?

Given a string and we have to check whether it is ending with a given substring or not?


This method checks whether string is ending with given substring or not?


Bool String.EndsWith(String subStr);

subStr is the substring to be checked.
Bool is the Boolean value, it’s a return type of this method, if string is ending with substring subStr method will return true and if it is not ending with substring subStr method will return false.

Consider the program:

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

namespace ConsoleApplication1
    class Program
        static void Main()
            String str1; 
            bool flag = false;

            Console.Write("Enter String : ");
            str1 = Console.ReadLine();
            flag = str1.EndsWith("india");
                Console.WriteLine("String ends with india");
                Console.WriteLine("String does not end with india");



Enter String : It is india
String ends with india

C# Basic Programs »


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.