Instead of this, use CSS `text-overflow` set to elipsis. See how we are doing that in returning search results for long names when adding persons to a group.