program for string reverse(eg:- i am boy -> boy am i)

Answers were Sorted based on User's Feedback



program for string reverse(eg:- i am boy -> boy am i)..

Answer / pratik

public string Reverse(string str)
{
// convert the string to char array
char[] charArray = str.ToCharArray();
int len = str.Length - 1;
/*
now this for is a bit unconventional at first glance because there
are 2 variables that we're changing values of: i++ and len--.
the order of them is irrelevant. so basicaly we're going with i from
start to end of the array. with len we're shortening the array by one
each time. this is probably understandable.
*/
for (int i = 0; i < len; i++, len--)
{
/*
now this is the tricky part people that should know about it don't.
look at the table below to see what's going on exactly here.
*/
charArray[i] ^= charArray[len];
charArray[len] ^= charArray[i];
charArray[i] ^= charArray[len];
}
return new string(charArray);
}

Is This Answer Correct ?    4 Yes 1 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / sudhir2884

class Program
{
static void Main(string[] args)
{

string str = "i am a good boy";
string[] strarray = str.Split(' ');
for (int i = strarray.Length-1; i>=0; i--)
{
Console.WriteLine(strarray[i]);
}
Console.ReadLine();
}
}

Is This Answer Correct ?    5 Yes 2 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / praveen kumar

class Program
{
static void Main(string[] args)
{
string s = "I AM A BOY";
for (int i = 0; i < s.Length; i++)
{
Console.Write(s[s.Length-i-1]);
}

Console.ReadLine();
}

Is This Answer Correct ?    3 Yes 2 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / ranjith m

private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = textBox1.Text;
richTextBox1.Text+=Environment.NewLine;
char[] wordarray = textBox1.Text.ToCharArray();
Array.Reverse(wordarray);
string s = new string(wordarray);
richTextBox1.Text += s;

}

Is This Answer Correct ?    1 Yes 0 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / jayakrishnan

var s1 = s.Split(' ').Reverse();
Console.WriteLine(string.Join(" " , s1.ToArray()));

Is This Answer Correct ?    1 Yes 1 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / mitali mishra

dim str1 as string= "i am boy"
dim str_arr() as string= str1.split(" ")
dim str2 as string
for i as integer = str_arr.length-1; i<=0; i--
str2 = str2.concat(str_arr(i) & " ")
end for
str2 = str2.removeat(str2.length-1)
str1 = str2

Is This Answer Correct ?    1 Yes 2 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / munagapati

string str = "I am an employee of Mindtree";
//string str1;
StringBuilder sb = new StringBuilder();
for (int i = str.Length - 1; i >= 0; i--)
{
if (str[i].Equals(' '))
{
int j = i + 1;
sb.Append(str.Substring(j).Trim());
sb.Append(" ");
str = str.Remove(j);
//while (str[j])
//{
// sb.Append(str[j].ToString());
// j++;

//}

}

}
sb.Append(str);
Console.WriteLine(sb);
Console.ReadLine();

Is This Answer Correct ?    1 Yes 2 No

program for string reverse(eg:- i am boy -> boy am i)..

Answer / guest

reverse()

Is This Answer Correct ?    8 Yes 16 No

Post New Answer

More C Sharp Code Interview Questions

Write a program which has a function and that function should take 2 or 3 or any number of strings and it should return the largest common prefix of all those strings. If there is no common prefix it should return an empty string. for eg:- INPUT OUTPUT glo {glory,glorious,glod} gl {glad,glow} {calendar,phone} empty string

2 Answers   Mind Tree,


Write a function which accepts list of nouns as input parameter and return the same list in the plural form. Conditions: i) if last letter is r then append s ii) if word ends with y then replace it by ies iii) call this function in main() and produce the required output. for eg:- if chair is input it should give chairs as output.

0 Answers   Mind Tree,


How to find No of classes,Packages,No of Methods per Classes and Depth of Inheritance for selecting source code in windows form application using c# .net? (Source code is input Program. It may be Java or .net) Please help me..) Thanks..)

0 Answers  


IS Array list is generic or non generic

1 Answers  


c# code to Count number of 1's in a given range of integer (0 to n)

0 Answers  






program to reverse the order of words in a string.

2 Answers   Mind Tree,


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


Code for Working with Files under a Directory?

1 Answers  


Create a class called Accounts which has data members like ACCOUNT no, Customer name, Account type, Transaction type (d/w), amount, balance D->Deposit W->Withdrawal If transaction type is deposit call the credit(int amount) and update balance in this method. If transaction type is withdraw call debit(int amt) and update balance. Pass the other information like Account no,name,Account Type through constructor. Call the show data method to display the values.

1 Answers   Cognizant,


Code for Reading and writing from a file?

0 Answers   IBM, Xoriant,


How to pass multiple rows from one gridview to another gridview after clicking the checkbox.

1 Answers   Satyam,


Code for Reading and writing from a file in c#?

1 Answers  


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)