Не удается проверить, является ли индекс действительным.
int endIndex = input.IndexOf("/") + (("/").Length)-1;
endIndex
равно -1, если '/' не существует.
// endIndex - startIndex is less than 0;
input.Substring(startIndex, endIndex - startIndex),
Я копирую ваш код ниже и оставляйте комментарии о позиции.
public async Task WaitForInputAsync()
{
while(true)
{
Console.Write("Enter Command: ");
Console.ForegroundColor = ConsoleColor.White;
var input = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.DarkCyan;
var split = input.IndexOf(" ");
// This could be -1 if '/' is not found
var indexOfChar = input.IndexOf('/');
int startIndex = input.IndexOf(input.Substring(split + 1));
int endIndex = input.IndexOf("/") + (("/").Length)-1;
if (split >= 0)
{
await ProcessCommandAsync(input.Substring(0, split),
// endIndex - startIndex is less than 0;
input.Substring(startIndex, endIndex - startIndex),
input.Substring(indexOfChar + 1));
}
else
{
await ProcessCommandAsync(input);
}
}
}
Однако я предлагаю взглянуть на ответ @DrkDeveloper, команда разбора - боль в шее ..