Retrieve accents in C #

3

I can not retrieve a text with a tilde in StringBuilder of

The silly example would be this:

System.Text.StringBuilder sbEx = new System.Text.StringBuilder();
sbEx.Append("<br />Hoy es día " + dia.ToShortDateString() + ".");
return sbEx.ToString();

This code returns "Hoy es día 03/07/2017" .

How can I retrieve the tilde?

    
asked by MKP 03.07.2017 в 12:06
source

2 answers

1

This is mostly caused by lack of UTF-8 coding to the web pages:

<html>
  <head>
    <meta charset="utf-8">
  </head>
</html>

In cristalab.com you can find more information.

    
answered by 03.07.2017 в 14:59
1

For some reason you are taking the charset badly, try to translate-it

byte[] bytes = Encoding.Default.GetBytes(str);
str = Encoding.UTF8.GetString(bytes);
    
answered by 06.07.2017 в 11:36