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
What is a thicknet?
pashok25 [27]
A type of coaxial cable
7 0
3 years ago
You are designing a wireless network for a client. Your client needs the network to support a data rate of at least 54Mbps. In a
mariarad [96]

Answer:

The best choice is 802.11a.

Explanation:

The most common option, that is widely used in home internet is 802.11b, however, this only supports a max speed of 11Mbps.

802.11a supports up to 54Mbps and it has regulated frequencies that prevent interference from other devices, such as the wireless system that your client already has. This option is more expensive, and its signal has issues going through walls and rooms but still, it is the one that fits him the most.

4 0
3 years ago
Pls help me awnser this I will give points
joja [24]

Answer:

first one is "int" second one is "string" and third one should be "float"

Explanation:

not sure if the first one is right but try this.

6 0
3 years ago
When you record a macro, all of the actions are converted by the program to code
Yuri [45]

Yes you are creating a list of actions based off the previous

5 0
3 years ago
Read 2 more answers
A hacker using information gathered from sniffing network traffic uses your banking credentials from a recent transaction to cre
adell [148]

Answer: a replay attack, a replay attack is used so that the attacker can go sniff out the hash, and get whatever they are trying to get, then once it goes to the attacker it will go back to the original connection after replaying the hash

3 0
3 years ago
Other questions:
  • Can someone please help me with this
    9·1 answer
  • The highly advanced decision support feature integrated within an electronic information system would support which activity?
    9·1 answer
  • The following if statement uses an overloaded > operator to determine whether the price of a Car object is more than $5000. C
    15·1 answer
  • What is the output of the following code? stackList stack; int x, y; x = 2; y = 3; stack.push(8); stack.push(x); stack.push(x +
    6·1 answer
  • Why are some geo satellites not usually used for transmitting tcp/ip information?
    5·1 answer
  • III. FILL-IN THE BLANK (five points each)
    14·1 answer
  • Switched backbone networks:_____.a. always use a ring topology.b. require much more management that do routed backbone networks.
    10·1 answer
  • Could anyone help me with this assignment please?
    6·1 answer
  • Im a beginner programmer. what languages should i learn and how do i get better
    13·1 answer
  • This seems like a good time to ask the basic question, “How’s it going in class?” Feel free to offer constructive feedback about
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!