Blockquote
I've have successfully gotten my code to read in the text from an external file and display it. I've also got code for a simple Caesar shift. I just don't know how to get my code to read in the file and then perform the Caesar shift and display the output after the caesar shift, can someone please help. Here is my code:
using System;
using System.IO;
class Shift
{
public static void Main(string [] args)
{
//Read in code to shift from text file.
string file = @"txt"; //I have a file linked here
string text = File.ReadAllText(file);
//Show original unshifted code.
System.Console.WriteLine("Original text reads: \n\n{0}", text);
//Show text after shift.
Console.WriteLine("The shifted code is: \n\n{1}", b);
//Start Caesar Shift code as a seperate method.
}
public static string Caesar(string value, int shift)
{
char[] buffer = value.ToCharArray();
for (int i = 0; i < buffer.Length; i++)
{
char letter = buffer[i];
letter = (char)(letter + shift);
if (letter > 'z')
{
letter = (char)(letter - 26);
}
else if (letter < 'a')
{
letter = (char)(letter + 26);
}
// Store shift.
buffer[i] = letter;
}
return new string(buffer);
}
//Add number to shift text.
public static void Second()
{
string a = text;
string b = Caesar(a, 18);
}
}
You are almost there. Look at the last Console.WriteLine in the snippet below.
public static void Main(string[] args)
{
//Read in code to shift from text file.
var file = @"txt"; //I have a file linked here
var text = File.ReadAllText(file);
//Show original unshifted code.
Console.WriteLine("Original text reads: \n\n{0}", text);
//Show text after shift.
Console.WriteLine("The shifted code is: \n\n{0}", Caesar(text, 18));
}