C# Program to reverse each word in a string ?

Posted by Nav234 under C# on 9/22/2010 | Points: 10 | Views : 6791 | Status : [Member] | Replies : 2
Hi all,

Write a C# program to reverse each word in a string
help on this issue also.

Thanks in advance

S.Naveen...


Responses

Posted by: Rajumm on: 9/22/2010 [Member] Starter | Points: 25

Up
0
Down
http://www.dotnetobject.com/showthread.php?tid=218

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Peermohamedmydeen on: 9/23/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi Naveen,

We can achieve the string reversal in a easy way.

Let us Consider a one dimensional character array, input string and an output string variable.

Char[] arrStr; 

string strInput = "Naveen";
string strOutput= string.Empty;


Am passing the string "Naveen" to the array in the following manner.

arrStr = strInput.ToCharArray();


then we have to put a reverse for loop like below

for(int idx=arrStr.Length-1;idx>=0; idx--)

{
strOutput += arrStr.Getvalue(idx);
}



The output will be "neevaN"


Note : If you want to reverse each word, split by space and put in another array do the same operation for each item in the array and show.




Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response