Q:

Write a C# program to check whether a given substring is present in the given string

0

Write a C# program to check whether a given substring is present in the given string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
public class Stringexercise
{
    public static void Main()
    {
        string str1, str2;
        bool m;
 
        Console.Write("Enter the string : ");
        str1 = Console.ReadLine();
 
        Console.Write("Input the substring to  search : ");
        str2 = Console.ReadLine();
        m = str1.Contains(str2); 
        if (m) // check boolean value is true or false.
            Console.WriteLine("The substring exists in the string.");
        else
            Console.WriteLine("The substring is not exists in the string.");
 
        Console.ReadLine();
    }
}

Result:

Enter the string : techstudy - the complete debugging solution

Input the substring to  search : techstudy

The substring exists in the string.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< Write a C# program to read a sentence and replace ...