Updated trimlink function for autodetect encoding

Updated trimlink function for autodetect encoding, Thank you SchreiBear