C# String substring exists

In this article we will discuss about how to test whether the particular string exists or not.
  • 4993

The Contains method returns true if a substring is a part a string. The following code snippet checks if a substring exists in a string.

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 = "author";
            bool b = sentence.Contains(findString);
            Console.WriteLine("String exists: {0}", 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.