Home » .Net

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?

String.EndsWith()

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

Syntax:

Bool String.EndsWith(String subStr);

Here,
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");
            
            if(flag==true)
                Console.WriteLine("String ends with india");
            else
                Console.WriteLine("String does not end with india");

        }
    }
  
}

Output

Enter String : It is india
String ends with india





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







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

© https://www.includehelp.com some rights reserved.