1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Fed [463]
4 years ago
5

Write a function called replace_at_index that takes three arguments - a string, an integer (representing an index), and a string

. Return a string that is the same as the first string, except with the character at the specified index replaced by the second string.
Ask the user for some text, which index to replace, and what to replace that index with (in that order!).

Print out the result of calling your function.
Computers and Technology
1 answer:
Zigmanuir [339]4 years ago
3 0

Answer:

The program in csharp is given below.

using System;

class Test

{

   //variables required to hold the strings and index

    static string line;

    static string test;

    static int idx;

    static string final="";

    static string replace_at_index(string str, int index, string s)

    {

        //replacement string inserted at the required position

        final = line.Insert(idx, test);

        //extra characters removed

        final = final.Remove(idx+test.Length, test.Length);

        return final;

    }

    static void Main()

    {

        Console.WriteLine("Enter a sentence");

        line = Console.ReadLine();

        Console.WriteLine("Enter the index to replace the string");

        idx = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Enter the replacement string");

        test = Console.ReadLine();

        //the resultant string displayed

        Console.WriteLine("The string after replacement is "+ replace_at_index(line, idx, test));

    }    

}

OUTPUT

Enter a sentence

i am working now.

Enter the index to replace the string

3

Enter the replacement string

not

The string after replacement is i anotorking now.

Explanation:

1. Declare the variables to hold the user inputted strings, the index and the resultant string.

2. The variables are declared outside Main() and hence declared as static.

3. Inside Main(), user input is taken for the original string, the index to be replaced and the new replacement string.

4. Define the method, replace_at_index() that takes all the three user entered values as parameters and return the resultant string.

5. Inside replace_at_index() method, the replacement string is inserted into the original string at the required position using insert() method.

6. The resultant string is stored in the variable, final.

7. After insert(), remove() method removes the original character(s) which got shifted after the insert() operation.

8. The replace_at_index() method returns the resultant string having the replaced string inserted in the original string.

9. The whole code is written inside class as csharp is purely object-oriented language.

10. No object of any class is created since only a single class is involved.

11. The string operations have been done using the in-built string functions of csharp language.

12. The index of the string begins with 0 hence the string operations work accordingly.

You might be interested in
Why is color important for all objects drawn ?​
Sati [7]
Technically, drawing in colored pencil is simply layering semitransparent colors on paper to create vivid paintings. Every color has three qualities
7 0
3 years ago
Is this statement true or false?
____ [38]
This answer could be either, but personally false. Humor drives attention into your work (if the humor isn’t about it then yes it would drive it far off) but it makes people focus and listen to your presentation so they would answer your jokes. Hope this helped!
7 0
3 years ago
2. What is the layout of the modern keyboard known as?
lukranit [14]

Answer: QWERTY

Explanation:

QWERTY is a keyboard design for Latin-script alphabets. The name comes from the order of the first six keys on the top left letter row of the keyboard ( Q W E R T Y )

6 0
3 years ago
We are supposed to go to the concert tomorrow, but it has been raining for three days straight. I just know that we won’t be abl
Mumz [18]

Its the worried tone

Hope this helps!

3 0
3 years ago
Read 2 more answers
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
qaws [65]

Answer:

Se explaination

Explanation:

/Declaring variables

integer currentPrice

integer lastMonthPrice

integer changeLastMonth

float mortagage

//Reading input

currentPrice = Get next input

lastMonthPrice = Get next input

//Calculating price change

changeLastMonth = currentPrice - lastMonthPrice

//Calculating mortagage

mortagage = (currentPrice * 0.051) / 12

//Printing output

Put "This house is $" to output

Put currentPrice to output

Put "\nThe change is $" to output

Put changeLastMonth to output

Put " since last month." to output

Put "\nThe estimated monthly mortgage is $" to output

Put mortagage to output

3 0
3 years ago
Other questions:
  • Ponce is the largest city on which coast of Puerto Rico
    13·1 answer
  • What is the answer to this question on the thing I'm doing in apex
    6·1 answer
  • When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
    11·1 answer
  • Explain the concept of scalability. How would you respond?
    15·1 answer
  • Which is a disadvantage ofsimulation?
    5·1 answer
  • Weak Induction
    8·1 answer
  • Savings accounts _____.
    15·1 answer
  • Computers were originally developed to accomplish various tasks in relative isolation, very different from the collaboration and
    14·1 answer
  • an existing technology that would allow users to transfer images from the camera to the computer without connecting them
    8·1 answer
  • Write a program in c# that simulates the roll of two six sided dice.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!