【问题标题】:VCF file stream to c#VCF文件流到c#
【发布时间】:2013-04-11 10:30:51
【问题描述】:
我有一个 VCF 文件,其中包含我的整个电话簿。我用记事本打开它,并通过 StreamReader 将数据传输到 c# 中的 windows 窗体。一些 vcard 条目包含如下一行:
"N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=42=75=72=73=61=6C=C4=B1;=4D=75=73=74=61=66=61; ;;"
看起来该行是 UTF-8 代码字符集,但我不知道如何将其转换为字符串。
感谢您的建议。
【问题讨论】:
标签:
utf-8
character-encoding
vcf-vcard
【解决方案1】:
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
}
}
如何从文件中提取 "UTF-8" 和 "=42=75=72=73=61=6C=C4=B1;=4D=75=73=74=61=66=61" 部分留给您练习:P
【解决方案2】:
属性值采用quoted-printable 编码,这是一种标准编码机制。您也许可以找到一个可以为您解码的库。另外,试试this SO thread。