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
VulpesPosted May 19, 2011, 4:19 AM
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();
abood netPosted May 19, 2011, 4:26 AM
abood netPosted May 19, 2011, 4:02 AM
Posted May 19, 2011, 3:39 AM
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 netPosted May 19, 2011, 3:16 AM
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!?
FroglegPosted May 19, 2011, 3:06 AM
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);
}