Can I run this program without dupilcating the code as below?
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace textAnalyser
{
public class Analyser
{
public static void Main()
{
// Values 
string myScen;
string newScen = "";
int numbChar = 0;
string userInput;
//User decsion on how to data is inputted
Console.WriteLine("Enter k for keyboard and r for read from file");
userInput = Convert.ToString(Console.ReadLine());

//If statement, User input is excecuted
// User enters their statment
if (userInput == "k")
{
Console.WriteLine("Enter your statment");
myScen = Console.ReadLine();

// Does the scentence end with a full stop?

if (myScen.EndsWith("."))
{
Console.WriteLine("\n\tScentence Ended Correctly");
</code></pre>

<p>Character calculation code 1, this is repeated for if the user chooses to read from a file, Can this be done without using this code more than once?</p>

<pre><code>// Then Calculate number of characters
foreach (char c in myScen)
{
numbChar++;
if (c == ' ')
continue;

newScen += c;
}
Console.WriteLine("\n\tThere are {0} characters. \n\n\n", numbChar);
}
else
Console.WriteLine("Invalid Scentence");
}
</code></pre>

<p>Code for Read file, Can i not duplicate couting the number of characters?</p>

<pre><code>else
if (userInput == "r")
{
//Reads from a text file
string file = @"C:\Users\Jordan\Documents\SoftDev\myText.txt";

string text = File.ReadAllText(file);

//Displays the text file
System.Console.WriteLine("Contents of myText.txt: \n\n{0}", text);

// Calculate number of characters
foreach (char c in text)
{
numbChar++;
if (c == ' ')
continue;

newScen += c;
}
 Console.WriteLine("\n\tThere are {0} characters. \n\n\n", numbChar);
}

}
}
}
</code></pre>
