Arthur, I rewrote a new way to truncate strings, please give it a look. It is with clear comments about my implementation.