Encoding.GetEncoding ("Cyrillic") créant tous les points d'interrogation de texte dans .NET

Oct 16 2020

Pourquoi le txt đ—œđ—Ąđ——đ—ąđ—ąđ—„ 𝗩𝗱𝗙𝗧𝗕𝗔𝗟𝗟 đ—§đ—ąđ—šđ—„đ—Ąđ—”đ— đ—˜đ—Ąđ—§ 𝗗𝗜𝗔𝗠𝗱𝗡𝗗 đ—đ—”đ—«đ—« 𝗔𝗡𝗗 𝗛𝗜𝗧𝗭est-il converti en txt avec la mĂ©thode ci-dessous?

???????????? ???????????????? ???????????????????? ?????????????? ???????? ?????? ????????

Je crois que cela ne s'est pas produit avant mais je l'ai juste vu faire. J'utilise .NET 4.8.

 public static string RemoveAccent(this string txt)

    {
        if(txt == null)
        return txt;

        byte[] bytes = Encoding.GetEncoding("Cyrillic").GetBytes(txt);
        return Encoding.ASCII.GetString(bytes);
    }

Réponses

MikeFlynn Oct 16 2020 at 23:36

Le texte était dans une sorte de codage Unicode et pourquoi il agissait différemment avant avec du texte codé ASCII. J'ai donc fait cela ci-dessous avant le GetEncoding et cela fonctionne maintenant.

if(!txt.IsNormalized(NormalizationForm.FormKD))
            {
                txt= txt.Normalize(NormalizationForm.FormKD);
            }