Read In External File Then Display After Caesar Shift

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); 
    }
}

Answers


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));
}

Need Your Help

Getting A Garbage Value In Bubble Sorting for the Highest Value in C

c sorting

I am facing a problem that the Highest value in the array is getting replaced by a random garbage negative value. I am not able to locate the problem. Here is the full source code to the program -

Windows Workflow Foundation 4 (WF4) Delay

windows workflow workflow-foundation-4 delay

I'm working with the the Release Candidate of Visual Studio 2010 using Wf4 to write a new workflow for approving resource requests. In my workflow, I would like for a request to expire after a few...