VCF Vcard导入C# [英] VCF Vcard import c#
问题描述
我试图编写一个导入* .vcf文件(Vcard)的类,因为我没有找到足够的.net类来解决该工作.
iam trying to write a class which imports *.vcf files (Vcard), because i didn´t found a adequate .net class to solve that job.
因此,我决定将* .vcf文件视为* .txt文件.我只是使用StreamReader逐行导入整个文件.最后,我将该行保存到一个List对象中.
So i decided to treat the *.vcf file like a *.txt file. I just import the whole file, line by line, with a StreamReader. Finally i save the line into a List object.
代码:
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:
After importing the text i needed to edit the lines, because i need to remove all the unnecessary symbols. I tried to use the RedEx claa:
private void button1_Click(object sender, EventArgs e)
{
vcardList[0] = Regex.Replace(vcardList[0], "BEGIN:", string.Empty);
}
效果很好,对于第一行!但是* .vcf文件非常复杂且始终存在差异.
that works very well, for the first line! but the *.vcf file is very complex and allways different.
所以我的问题是:是否有更好的方法来解决该问题?
So my question is: Is there a better way to solve that problem?
这是* .vcf文件:
This is the *.vcf file:
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
我只需要姓名和地址.预先感谢
I only need the name and address. Thanks in advance
推荐答案
虽然很旧,但仍然可以使用: https://github.com/drlongnecker/Thought.vCards
Pretty old, but it still works: https://github.com/drlongnecker/Thought.vCards
这篇关于VCF Vcard导入C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!