Click here to Skip to main content
14,271,130 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

hi
string yourString = "blablabla";
char[] array = yourString.ToCharArray();
Array.Reverse(array);
string yourStringReverse = array.ToString(); //[thanks for the note ProEnggSoft]
string yourStringReverse = String.Join("",array);
   
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
Rate this:
Please Sign up or sign in to vote.

Solution 4

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
string reversedString = new string("abcd".ToCharArray().Reverse().ToArray());
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100