Detecting and converting character encodings