using System.Collections.Generic;
public static void Main()
foreach (var limit in new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}){
Console.WriteLine(Truncate("Hello world this is a text string of epic proportions indeed", limit));
private const string Ellipsis = "...";
public static string Truncate(string text, int charLimit)
if (string.IsNullOrWhiteSpace(text)) return string.Empty;
if (text.Length <= charLimit) return text;
text = text.Substring(0, charLimit);
var lastIndex = text.LastIndexOf(' ');
lastIndex = charLimit - 1;
lastIndex = Math.Min(text.LastIndexOf(' ') - 1, charLimit - 1);
text = text.Substring(0, lastIndex + 1);