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

  • برمجة سي شارب
  • برمجة

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

Test Data :
Input the string : This is a Test String
Input the substring to search : Test
Expected Output :

The substring exists in the string

الأجوبة

using System;
public class exercise14
{
	public static void Main()
	{
  string str1,str2;
  bool m;	
       Console.Write("\n\nCheck whether a given substring is present in the given strig :\n");
       Console.Write("-------------------------------------------------------------------\n");	
        Console.Write("Input the string : ");
               str1 = Console.ReadLine();	
	    Console.Write("Input the substring to  search : ");
               str2 = Console.ReadLine();
               m=str1.Contains(str2); // boolean value tapped hare
    if (m) // check boolean value is true or false.
		Console.Write("The substring exists in the string.\n\n");
	else
		Console.Write("The substring is not exists in the string. \n\n");
	}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...