Also, you need to take into account the other characters which might constitute an end of word like ".", "!", "?" and end of line markers like carriage return and linefeed. If these characters could be part of your string you might consider replacing them with a space prior to processing (after the first truncation) so your loop only has to look for a space.
Main Topics
Browse All Topics





by: jeflabaPosted on 2009-09-21 at 17:21:24ID: 25388851
I would create a function to return a truncated string from a passed string. The first step is to truncate the passed string to the desired size + 1. Then loop deleting the last character until the last character is a space then delete the space and return the truncated string. The reason you need to add 1 to the desired length is to handle one character words like "I" and "a."