Skip to content

Instantly share code, notes, and snippets.

@leandrocustodio
Created April 8, 2013 16:33
Show Gist options
  • Save leandrocustodio/5338223 to your computer and use it in GitHub Desktop.
Save leandrocustodio/5338223 to your computer and use it in GitHub Desktop.
Método para converter UTF8 para ISO-8859-1 C#
private string UTF8_to_ISO(string value)
{
Encoding isoEncoding = Encoding.GetEncoding("ISO-8859-1");
Encoding utfEncoding = Encoding.UTF8;
// Converte os bytes
byte[] bytesIso = utfEncoding.GetBytes(value);
// Obtém os bytes da string UTF
byte[] bytesUtf = Encoding.Convert(utfEncoding, isoEncoding, bytesIso);
// Obtém a string ISO a partir do array de bytes convertido
string textoISO = utfEncoding.GetString(bytesUtf);
return textoISO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment