📄 importcontactsfromvcard.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Common;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
internal class ImportContactsFromVcard : IImportContacts
{
private ImportContactType _type;
public string GetContactsXML(IWin32Window owner, string filePath)
{
StringBuilder builder = new StringBuilder();
builder.Append("<Contacts>");
using (StreamReader reader = new StreamReader(filePath, Encoding.Default, true))
{
string text;
if (!reader.ReadLine().ToUpper().Contains("BEGIN:VCARD"))
{
throw new NotSupportedException();
}
string text2 = "";
string text3 = "";
string text4 = "";
while ((text = reader.ReadLine()) != null)
{
if (text.StartsWith("TEL;CELL;VOICE:"))
{
text2 = text.Replace("TEL;CELL;VOICE:", "");
}
if (text.StartsWith("FN"))
{
string[] textArray = text.Split(new char[] { ':' });
text3 = textArray[textArray.Length - 1];
}
if (text.StartsWith("NICKNAME:"))
{
text4 = text.Replace("NICKNAME:", "");
}
}
if (text2 != "")
{
builder.Append("<Contact>");
builder.Append(string.Format("<MobileNo>{0}</MobileNo>", text2));
builder.Append(string.Format("<Name>{0}</Name>", text3));
builder.Append(string.Format("<Nickname>{0}</Nickname>", text4));
builder.Append("</Contact>");
}
}
builder.Append("</Contacts>");
return builder.ToString();
}
public string Filter
{
get
{
return "vcf files (*.vcf)|*.vcf";
}
}
public ImportContactType Type
{
get
{
return ImportContactType.VCard;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -