try
string filePath = @"D:\Tools\abc.txt";
string first5Words = "";
int maxWords = 5, count = 0;
using (StreamReader reader = new StreamReader(filePath))
{
while (reader.Peek() >= 0)
{
char c = (char)reader.Read();
char[] ChartoFindNewWord = { ' ', '\t', '\n', '\r' };
if(ChartoFindNewWord.Contains(c))
{
count++;
if(count >= maxWords)
break;
}
first5Words += c;
}
}
string output = first5Words;