[C#] Encoding Special Characters

Metodo comodo comodo per ritornare da iso-8859-1 utf-8 una stringa corretta:

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]/* return utf8 chars from iso-8859-1 */
string replaceSpecials(string special)
{
  if (special.Contains("Ã"))
  {
    Encoding utf_8 = Encoding.UTF8;
    byte[] bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(special);
    special = utf_8.GetString(bytes);
  }

  return special;
}[/code]

I diversi caratteri interpretati da Ã verranno convertiti nel valore corretto in formato UTF-8.

done.

[ref -> albertopasca.it]

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.