i need to print the first and the last word in a string here is what i've tried
Console.WriteLine("please enter a string");
string str = Console.ReadLine();
string first = str.Substring(0, str.IndexOf(" "));
string last = str.Substring(str.LastIndexOf(' '),str.Length-1);
Console.WriteLine(first + " " + last);
when i run the code this massage appear
Unhandled Exception: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length at System.String.Substring(Int32 startIndex, Int32 length) at ConsoleApp1.Tar13.Main() in C:\Users\User\source\repos\ConsoleApp1\ConsoleApp1\Tar13.cs:line 16
i dont know what is the problem