using System;
using System.Linq; // !! important
public class Program
{
public static void Main()
{
string phrase = Console.ReadLine();
int wordIndex = Convert.ToInt32(Console.ReadLine());
var result = phrase.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries)
.Skip(wordIndex - 1)
.FirstOrDefault();
Console.WriteLine(result ?? "N/A");
}
}
вывод:
>hello, this is a test
>3
is
Другая опция, тот же результат
var result = phrase.Split()
.Where(x => !string.IsNullOrWhiteSpace(x))
.Skip(wordIndex - 1)
.FirstOrDefault();