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);
            }