我正在尝试编写一个导入 *.vcf 文件(Vcard)的类,因为我没有找到足够的 .net 类来解决该工作。
所以我决定将 *.vcf 文件视为 *.txt 文件。我只是用 StreamReader 逐行导入整个文件。最后,我将该行保存到 List 对象中。
编码:
private List<string> vcardList = new List<String>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (StreamReader reader = new StreamReader(@"H:\VS.vcf"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
vcardList.Add(line);
}
}
}
导入文本后,我需要编辑这些行,因为我需要删除所有不必要的符号。我尝试使用 RedEx claa:
private void button1_Click(object sender, EventArgs e)
{
vcardList[0] = Regex.Replace(vcardList[0], "BEGIN:", string.Empty);
}
对于第一行,效果很好!但是 *.vcf 文件非常复杂并且总是不同的。
所以我的问题是:有没有更好的方法来解决这个问题?
这是 *.vcf 文件:
BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=de;CHARSET=Windows-1252:Test;Mustermann;;;(geschäftlich)
FN;CHARSET=Windows-1252:Test Mustermann (geschäftlich)
ORG:Mustermann CompanyTITLE;CHARSET=Windows-1252:CEO
TEL;WORK;VOICE:0049 1111 22 769 23 - 1
TEL;CELL;VOICE:0049 2222 33 71 55 90
ADR;WORK;PREF;CHARSET=Windows-1252:;;Frobuehl 22;Gothtown;;101092;England
LABEL;WORK;PREF;CHARSET=Windows-1252;ENCODING=QUOTED-PRINTABLE:Leihb=FChl 21=0D=0A=
101092 Frobuehl
X-MS-OL-DEFAULT-POSTAL-ADDRESS:2
URL;HOME:www.Test-Mustermann.de
EMAIL;PREF;INTERNET:Test@Test-Mustermann.de
X-MS-OL-DESIGN;CHARSET=utf-8:<card
END:VCARD
我只需要姓名和地址。提前致谢