Answer to Question #315993 in C# for skillie

Question #315993

Using visual studio (C#) to create a program, name it PRGYOURNAMEFA1, that implements a search and replace function recursively. Your program should allow a user to enter a string , a substring to be replaced in the entered string and a character/s to replace the found substring


Program Structure


1. A main class that implements the logic of the program – name this class TestSearchReplace


2. Add a class named SearchReplace to the main class with two methods, including:


a. SearchSubstring()- return method


b. ReplaceSubString() - void method


The two method should be called using an object in the main class. DONT CREATE THE TWO METHODS IN THE MAIN CLASS


Sample Output



1
Expert's answer
2022-03-22T15:21:53-0400
using System;
class TestSearchReplace
{
    static void Main()
    {
        Console.Write("Input string: ");
        string str = Console.ReadLine();
        Console.Write("Input substring for replace: ");
        string substr = Console.ReadLine();
        Console.Write("Input character/s to replace: ");
        string ch = Console.ReadLine();


        SearchReplace searchReplace = new();
        Console.WriteLine($"\nIndex of substring: {searchReplace.SearchSubstring(str, substr)}");
        searchReplace.ReplaceSubString(ref str, substr, ch);
        Console.WriteLine($"New string after replace: {str}");
    }
}


class SearchReplace
{
    public int SearchSubstring(string str, string substr)
        => str.IndexOf(substr);
    public void ReplaceSubString(ref string str, string substr, string ch)
        => str = str.Replace(substr, ch);
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS