Strip out characters that are invalid for a specified charset.