I would like to know how I can edit directly in the console application. I mean, when I open the application I will see "Edit the code : GW1020" and I want to set the cursor after zero and when the user presses backspace to delete zero to remain "Edit the code : GW102", how could I do that ? I tried overwriting but it doesn't work because I get zero at the end, this is the code as I tried to write it:
private void EditCode(string code)
{
Console.Clear();
Console.WriteLine("> Edit code: " + code);
Console.WriteLine();
Console.WriteLine("> Enter the Name: " + products[code].Name);
Console.WriteLine();
Console.WriteLine("> Enter the Quantity: " + products[code].Quantity);
Console.WriteLine();
Console.WriteLine("> Enter the UM: " + products[code].UM);
Console.WriteLine();
ConsoleKeyInfo info;
do
{
info = Console.ReadKey(true);
if (info.Key == ConsoleKey.Backspace && code.Length > 0)
{
code = code.Remove(code.Length - 1);
Console.CursorVisible = true;
Console.SetCursorPosition(0, 0);
Console.WriteLine("> Edit code: " + code);
Console.SetCursorPosition(20, 0);
}
else if (info.Key != ConsoleKey.Backspace && info.Key != ConsoleKey.Enter)
{
code += info.KeyChar;
Console.Write(info.KeyChar);
}
} while (info.Key != ConsoleKey.Enter);