We can use regular expression to get the first N words from a title or strings. The following example shows how it can be done.

This example utilizes RegularExpression namespace


using System.Text.RegularExpressions;

string testwords = "I want only first N words from this strings";

 string firstnWords = Regex.Match( testwords , @"^(\w+\b.*?){3}").ToString();

 label_Result.Text = firstnWords;


I want only