I'd need to get a html friendly version of a truncated Xhtmlstring as the tag endings might get clipped when truncated. Any ideas on how to achieve this? I've thought of just getting rid of all tags first and then clipping but is there a solution for this inside episerver or is this just basic string-manipulation with regex?
There is a built-in helper function in the TextIndexer class called StripHtml which can be used to remove any tags to end up with plain text before truncating:
var plainText = TextIndexer.StripHtml(someHtml);
Note that this method can also be used to truncate the string like so:
// Truncate to 150 characters
var truncatedString = TextIndexer.StripHtml(someHtml, 150);
You'll also be able to have a string such as "..." appended to the string if it was truncated.