Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Searching a string inside a string in C#

We can search and get the position of a string inside another string using IndexOf()

  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace forgetCode
  6. {
  7. class program1
  8. {
  9. static void Main(string[] args)
  10. {
  11. string baseString = "Forget code";
  12.  
  13. string subString = "get";
  14.  
  15. int iWhere = baseString.IndexOf(subString);
  16.  
  17. Console.WriteLine("Occurred at : " + iWhere +" position");
  18.  
  19. }
  20. }
  21. }


Output:
Occurred at : 3 position

..