Trims a string to a given length, including support for prefixes and suffixes