Im gone substring a description text after a certain count with .Substring(0, 100). I dont want to break in the middle of a word, if thats the case i would like to get to the first whitespace before the word.
I figure i check if the next character is not a " " its in the middle of the word.
My biggest issue is how do step backwards to get the index of the " " (whitespace).
this is what i got so far
string description = "a long string";
description = Regex.Replace(description, @"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", String.Empty);
var newString = (description.Count() > 101) ? description.Substring(0, 101) : description;
//i tried something like this
var whatIsNext = newString.IndexOf(" ", 100, -20);
I think you’re looking for
String.LastIndexOf:You want something like this: