Here is a C# Interview question I faced in an interview. This is very easy. But, I am sharing just to make all of you aware of this type of questions being asked in interviews.
public static string xReverse(string inputStr)
{
int len = inputStr.Length;
StringBuilder revStr = new StringBuilder();
for (int i = len - 1; i >= 0; i--)
{
revStr.Append(inputStr[i]);
if (i != 0)
{
revStr.Append('X');
}
}
return revStr.ToString();
}
If anybody has any other solution or has a better idea, please share as comments.
Question:
Write a function named XReverse in C# that will take a string as input and return the reverse of the string with 'X' in between each characters as Output.Solution Code:
public static string xReverse(string inputStr)
{
int len = inputStr.Length;
StringBuilder revStr = new StringBuilder();
for (int i = len - 1; i >= 0; i--)
{
revStr.Append(inputStr[i]);
if (i != 0)
{
revStr.Append('X');
}
}
return revStr.ToString();
}
Output:
If anybody has any other solution or has a better idea, please share as comments.
Same question is been asked by ITC infotech last week
ReplyDelete