27.10.07

Programming Question

Question:

Write a function/subroutine in a language that you are familiar with that will replace all occurrences of "we" to "you" in the following phrase: "If we try our best, and we devote our full energy to the task, we will succeed". You must do this without using the Replace function.

Answers:

Applicant 1:

string txtvalue;
string txtvalue2;

txtvalue = "If we try our best, and we devote our full energy to the task, we will succeed".
txtvalue2 = "If you try our best, and you devote our full energy to the task, you will succeed".

txtvalue = txtvalue2;

return txtvalue;

Applicant 2:

string x = "If we try our best, and we devote our full energy to the task, we will succeed".'
string y = "you";

x.ChangeValue("we", y);

return x;

No comments: