public void Start() { TextFormater tf = new TextFormater(); String config; config = ConfigurationManager.AppSettings["config"]; // choose from where take text if (config.Equals("file")) { String path; String pattern = @"^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$"; Console.WriteLine("Enter path to file with text"); while (!Regex.IsMatch((path = Console.ReadLine()), pattern, RegexOptions.IgnoreCase)) { Console.WriteLine("Invalid enter"); } tf.FileLogic(path); } if (config.Equals("console")) { tf.ConsoleLogic(); } Console.ReadLine(); }
// work with console public void ConsoleLogic() { Console.WriteLine("Enter text"); String text = Console.ReadLine(); TextFormater tf = new TextFormater(); text = tf.ToLowerCase(text); Console.WriteLine(text); text = tf.ToLineBreak(text); Console.WriteLine(text); }
// work with file public void FileLogic(String path) { try { String text = File.ReadAllText(path); //Console.WriteLine(text); TextFormater tf = new TextFormater(); text = tf.ToLowerCase(text); Console.WriteLine(text); text = tf.ToLineBreak(text); Console.WriteLine(text); } catch (Exception e) { Console.WriteLine("File not found"); //Console.WriteLine(e); } }