Question

I have a VCF file that contains my entire phonebook. I open it with Notepad and transferring data to windows form in c# via StreamReader. Some of vcard entries contains a row like:

"N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=42=75=72=73=61=6C=C4=B1;=4D=75=73=74=61=66=61;;;"

It looks like the line is UTF-8 code charset, but I have no idea how to convert it to a string.

Thanks for any advice.

Était-ce utile?

La solution

using System.Net.Mail;

class Test
{

    public static string QPDecode(String str, String encoding)
    {
        Attachment attachment = Attachment.CreateAttachmentFromString("", "=?" + encoding + "?Q?" + str + "?=");
        return attachment.Name;
    }


    public static void Main(string[] args)
    {

        Console.WriteLine(QPDecode("=42=75=72=73=61=6C=C4=B1;=4D=75=73=74=61=66=61", "UTF-8"));
        //Bursalı;Mustafa

    }

}

How to extract the parts "UTF-8" and "=42=75=72=73=61=6C=C4=B1;=4D=75=73=74=61=66=61" from your file is left exercise to you :P

Autres conseils

The property value is in quoted-printable encoding, which is a standard encoding mechanism. You may be able to find a library that can decode it for you. Also, try this SO thread.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top