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]
3 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]3 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 the next line? >>> tupleB = (5, 7, 5, 10, 2, 7) >>> tupleB.count(7) 1 0 5 2
dybincka [34]

Answer:

The right answer is option 4: 2

Explanation:

Lists are used in Python to store elements of same or different data types.

Different functions are used in Python on List. One of them is count.

Count is used to count how many times a specific value occurs in a list.

The syntax for count is:

listname.count(value)

In the given code,

The output will be 2

Hence,

The right answer is option 4: 2

3 0
2 years ago
2.4 Code Practice: Question 1
USPshnik [31]

Answer:

num = float(input("Enter a number : "))

ab = abs(num)

sqrt = float(ab ** 0.5)

print(sqrt)

Explanation:

6 0
3 years ago
How do a tubercolosis test work?
Soloha48 [4]
The answer is If a skin or blood TB test is posittive, your doctore mau give you a chest X-ray. They will look for abnormal spots on your lungs or any changes caused by TB.
4 0
3 years ago
you have a shop in Salem, Illinois, that sells specialty chocolates. Some customers from France have started placing orders. Whi
Vladimir79 [104]

The data regulation which you must adhere to for your sales to France is known as: D. the General Data Protection Regulation.

<h3>What is GDPR?</h3>

GDPR is an acronym for General Data Protection Regulation and it can be defined as a legal framework that was enforced on the 25th of May 2018, so as to sets guidelines for business firms during the collection, processing and use of personal information from individuals that are residing in the European Union (EU) and the European Economic Area such as:

  • Germany
  • France
  • England
  • Spain

This ultimately implies that, the General Data Protection Regulation is a data regulation which you must adhere to for your sales to France.

Read more on GDPR here: brainly.com/question/27416494

#SPJ1

4 0
2 years ago
This may vary in your state, but S/P2 recommends keeping all environmental documentation a minimum of:
Anettt [7]

A would be the answer!!!...

4 0
3 years ago
Read 2 more answers
Other questions:
  • Sam has sent Sally an email. Sally wants to answer him without manually typing in his email address. Which email option should s
    12·2 answers
  • Explain what mistake Miranda made in the following scenario. Situation: Miranda suspects that there may be a problem with the ha
    13·2 answers
  • A. true
    6·1 answer
  • Write a method called printRange that accepts two integers as arguments and prints the sequence of numbers between the two argum
    6·1 answer
  • ___________ is a task pane used to correct grammar errors; opens when you click the Spelling &amp; Grammar button in the Proofin
    15·2 answers
  • 1. A database table can hold ??
    9·1 answer
  • QUESTIONS Which of the following use cases are suitable for compute-optimized cloud offering? ОА. None of the listed O B. Highly
    12·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • Write a program that removes all non-alphabetic characters from the given input.
    7·1 answer
  • True or false FAFSA awards work study, but jobspeaker can be used to learn which jobs are available
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!