Encoding.GetEncoding ("Cyrillic"), das alle Text-Fragezeichen in .NET erstellt
Oct 16 2020
Warum wird der Text 𝗜𝗡𝗗𝗢𝗢𝗥 𝗦𝗢𝗙𝗧𝗕𝗔𝗟𝗟 𝗧𝗢𝗨𝗥𝗡𝗔𝗠𝗘𝗡𝗧 𝗗𝗜𝗔𝗠𝗢𝗡𝗗 𝗝𝗔𝗫𝗫 𝗔𝗡𝗗 𝗛𝗜𝗧𝗭mit der folgenden Methode in den Text konvertiert?
???????????? ???????????????? ???????????????????? ?????????????? ???????? ?????? ????????
Ich glaube, das ist vorher nicht passiert, aber ich habe es einfach gesehen. Ich verwende .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);
}
Antworten
MikeFlynn Oct 16 2020 at 23:36
Der Text hatte eine Art Unicode-Codierung und warum er sich anders verhält als zuvor mit ASCII-codiertem Text. Also habe ich das unten vor dem GetEncoding gemacht und es funktioniert jetzt.
if(!txt.IsNormalized(NormalizationForm.FormKD))
{
txt= txt.Normalize(NormalizationForm.FormKD);
}