华为导出电话本格式转换成标准

打算将华为手机的电话簿导出到群晖发现导入的格式有问题导致乱码
微信截图_20220709110417.png
用记事本打开文件发现,华为为了避免编码错误将所有编码格式转成ASCII格式并在前著名格式,这就会导致引起其他平台不支持从而中文显示乱码。
微信截图_20220709110507.png
微信截图_20220709110709.png

 static string DecodeQuotedPrintable(string input, string charSet)
    {
        Encoding enc;
        try
        {
            enc = Encoding.GetEncoding(charSet);
        }
        catch
        {
            enc = new UTF8Encoding();
        }
        var occurences = new Regex(@"(=[0-9A-F]{2}){1,}", RegexOptions.Multiline);
        var matches = occurences.Matches(input);
        foreach (Match match in matches)
        {
            try
            {
                byte[] b = new byte[match.Groups[0].Value.Length / 3];
                for (int i = 0; i < match.Groups[0].Value.Length / 3; i++)
                {
                    Console.WriteLine(match.Groups[0].Value.Substring(i * 3 + 1, 2));
                    b[i] = byte.Parse(match.Groups[0].Value.Substring(i * 3 + 1, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                }
                char[] hexChar = enc.GetChars(b);
                input = input.Replace(match.Groups[0].Value, new String(hexChar));
            }
            catch(Exception E)
            { Console.WriteLine(E.Message); }
        }
        input = input.Replace("?=", "");
        return input;
    }
    static void Main(string[] args)
    {
        var sb = new StringBuilder();
        String[] texts = File.ReadAllLines(@"00002.vcf",Encoding.UTF8);
        String text = "";
        for (int i = 0; i < texts.Length; i++)
        {
            if (texts[i].IndexOf("UTF-8") > -1) text += DecodeQuotedPrintable(texts[i], "UTF_8") + "\r\n";
            else text += texts[i] + "\r\n";
        }
        File.WriteAllText(@"00003.vcf", text, Encoding.UTF8);
        Console.Read();
    }

微信截图_20220709110612.png

标签: none

添加新评论