I am trying to decode the text below by reversing it.
,sdreh ni dam og yeht taht nees eb lliw ti ;sdreh ni kniht neM"
".eno yb eno dna ,ylwols sesnes rieht revocer ylno yeht elihw
yakcaM selrahC
I used this code to do it.
String reed = File.ReadAllText("DecodeThis.txt");
char[] array1 = reed.ToCharArray();
Array.Reverse(array1);
Console.WriteLine(array1);
Console.ReadLine();
the output is:
"Charles Mackay
while they only recover their senses slowly, and on by one.?
?Men think in hards: it will be seen taht they go mad in herds"
I want the output to be
" Men think in hards: it will be seen taht they go mad in herds,
while they only recover their senses slowly, and on by one.
Charles Mackay"
How can i do that? please help

VulpesRank #55 · 29.2K reputationPosted May 19, 2011, 12:19 AM EDT
String reed = File.ReadAllText("DecodeThis.txt");
char[] array1 = reed.ToCharArray();
Array.Reverse(array1);
string[] lines = new String(array1).Replace("\r", "").Split('\n');
Array.Reverse(lines);
reed = String.Join("\r\n", lines);
Console.WriteLine(reed);
Console.ReadLine();
FroglegRank #1,020 · 1.9K reputationPosted May 18, 2011, 11:06 PM EDT
using (StreamReader sr = new StreamReader("DecodeThis.txt"))
{
String reed = sr.ReadLine();
String reed1 = sr.ReadLine();
String reed2 = sr.ReadLine();
char[] array1 = reed.ToCharArray();
char[] array2 = reed1.ToCharArray();
char[] array3 = reed2.ToCharArray();
Array.Reverse(array1);
Array.Reverse(array2);
Array.Reverse(array3);
Console.WriteLine(array1);
Console.WriteLine(array2);
Console.WriteLine(array3);
}
abood net7 reputationPosted May 18, 2011, 11:16 PM EDT
I know how to do it line by line using while loop but i was wondering if i can tweak my code to achieve the same results!?
Posted May 18, 2011, 11:39 PM EDT
StreamReader reader = new StreamReader("DecodeThis.txt");
while(true)
{
char[] array1 = reader.ReadLine().ToCharArray();
Array.Reverse(array1);
Console.WriteLine(array1);
}
reader.Close();
I am getting the output as
"Men think in herds; it will be seen that they go mad in herds,
while they only recover their senses slowly, and one by one."
Charles Mackay
Hope this helps you.
abood net7 reputationPosted May 19, 2011, 12:02 AM EDT
abood net7 reputationPosted May 19, 2011, 12:26 AM EDT