A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C# Sharp to search the position of a substring within a string
Q:

Write a program in C# Sharp to search the position of a substring within a string

0

Write a program in C# Sharp to search the position of a substring within a string. 
Test Data :
Input a String: this is a string
Input a substring to be found in the string: is
Expected Output :

Found 'is' in 'this is a string' at position 2

All Answers

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

using System;
public class Exercise17
{
   public static void Main()
   {  
       string str1;
	   string findstr;
       Console.Write("\n\nSearch the position of a substing within a string :\n");
       Console.Write("-------------------------------------------------------\n");    
			Console.Write("Input a String: ");
			str1 = Console.ReadLine();
 
			Console.Write("Input a substring to be found in the string: ");
			findstr = Console.ReadLine();   
      int index = str1.IndexOf(findstr);
	  if(index<0)
	  Console.WriteLine("The substring no found  in the given string \n");
	  else
      Console.WriteLine("Found '{0}' in '{1}' at position {2}",
                        findstr, str1, index);
   }
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now