문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top