我想知道如何通过按Enter
两次退出控制台中的应用程序
string userInput; // to display back the exact user input if format for the code has been incorrectly entered
string morseInput;
do
{
Console.WriteLine("Enter Morse Code: \n");
userInput = Console.ReadLine();
morseInput = userInput.Replace(" ","");
bool isValid = Regex.IsMatch(morseInput, @"^[-.]+$"); // only allow dots and dashes
if (isValid)
{
Console.WriteLine("\nAll permutations:");
var charString = new List<string>(Permutate(morseInput));
foreach (string character in charString)
Write(character);
}
else // Error for improper input format
{
if (morseInput.Length == 0)
Console.WriteLine("Morse can not be zero-length.");
else
{
Console.WriteLine("\nFormat of morse must be only dots and dashes");
Console.WriteLine("Parameter name: " + userInput + "\n");
}
}
Console.WriteLine("\n");
}
while (true);