You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
943 B
C#

using System;
public class Exercise20
{
public static void Main()
{
string str1;
string findstring;
string insertstring;
int i;
Console.Write("\n\nInsert a substing before the first occurence of a string :\n");
Console.Write("--------------------------------------------------------------\n");
Console.Write("Input the original string : ");
str1 = Console.ReadLine();
Console.Write("Input the string to be searched for : ");
findstring = Console.ReadLine();
Console.Write("Input the string to be inserted : ");
insertstring = Console.ReadLine();
i=str1.IndexOf(findstring); // locate the position of the first occurence of the string
insertstring = " " + insertstring.Trim() + " ";
str1 = str1.Insert(i, insertstring);
Console.Write("The modified string is : {0}\n\n",str1);
}
}