Trimming a string to shorten at an unspecified position.
Posted on 2006-07-06
1. variable length string, output from database
2. Need to display no MORE than 80 characters
3. Cannot end string on broken word (for instance, cutting at exactly 80 characters would be bad if it cuts a word in half)
The idea here is that I have a string from a field in a database. I want to trim it to 80 characters or as close to 80 without going over as I can get, without cutting any words in half.
To help, in ASP classic (which I'm converting from, to C#), I did it like this:
shortBody = Left(objRS(8), InStrRev(Left(objRS(8), 80), " "))
C# Only please.