How to use Contains() to check if one string contained in another with C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# modern programming";

            bool b = s.Contains("c#");
            Console.WriteLine(b);

            string s2 = "programming";
            if (s.Contains(s2))
                Console.WriteLine("yes");
            else
                Console.WriteLine("no");
        }
    }
}


/*
run:
     
True
yes
 
*/

 



answered Dec 22, 2016 by avibootz

Related questions

...