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


Introduction

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


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. public class Stringexercise
  3. {
  4. public static void Main()
  5. {
  6. string str1, str2;
  7. bool m;
  8.  
  9. Console.Write("Enter the string : ");
  10. str1 = Console.ReadLine();
  11.  
  12. Console.Write("Input the substring to search : ");
  13. str2 = Console.ReadLine();
  14. m = str1.Contains(str2);
  15. if (m) // check boolean value is true or false.
  16. Console.WriteLine("The substring exists in the string.");
  17. else
  18. Console.WriteLine("The substring is not exists in the string.");
  19.  
  20. Console.ReadLine();
  21. }
  22. }

Result

C# language techstudy

     





Related Topics




Popular Posts