Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would you split a string into characters in an array, reverse the order of the characters then display the reversed characters in a string again.

Im happy on how to split the string up and to reverse the order of the characters, but how do i display the chars as a string again?

Thanks for the help guys.
Posted

hi
C#
string yourString = "blablabla";
char[] array = yourString.ToCharArray();
Array.Reverse(array);
string yourStringReverse = array.ToString(); //[thanks for the note ProEnggSoft]
string yourStringReverse = String.Join("",array);
 
Share this answer
 
v3
Comments
sravani.v 5-Apr-12 6:45am    
My 5!
ProEnggSoft 5-Apr-12 7:09am    
Here array.ToString() gives System.Char[]. The constructor of string class can be used to obtain string from array of characters. Please see my solution (4).
ProEnggSoft 5-Apr-12 7:28am    
Now it's good answer. +5
nrgjack 5-Apr-12 7:43am    
heh thanks ^^ i have an override in my solution for the ToString() that's why it was working for me :p
 
Share this answer
 
One of the overloads of the constructor of string class takes array of characters as a parameter. So, the string can be obtained from array of characters as below
C#
string reversedString = new string("abcd".ToCharArray().Reverse().ToArray());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900