首页
/
每日頭條
/
科技
/
注釋過的vcf文件怎麼分析
注釋過的vcf文件怎麼分析
更新时间:2026-06-08 18:27:15

需要需要生成vcf 聯系人通訊錄,想到最快的是C# 做桌面應用程序,搜索了一下發現 contacts.vcf 文件其實就是文本,可以用記事本打開,格式如下

BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8;Encoding=QUOTED-PRINTABLE:Ben TEL;CELL:123546 END:VCARD

如果是多個就一直這樣排列下去;

public static void CreateCard(string name,string phoneNumber,bool isUtf8Encode) { String fileName = string.Format(@"D:/{0}_{1}.vcf", name, isUtf8Encode ? "Android":"windows"); FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("BEGIN:VCARD"); sw.WriteLine("VERSION:2.1"); sw.WriteLine("N;charSET=UTF-8;ENCODING=QUOTED-PRINTABLE:" EncodeQuotedPrintable(name, isUtf8Encode)); sw.WriteLine("TEL;CELL:" phoneNumber); sw.WriteLine("END:VCARD"); sw.Flush(); sw.Close(); fs.Close(); ; }

Quoted-Printable編碼定義,其實很簡單,就是将要編碼的文字轉換成byte字節流,然後使用十六進制的char型和“=”聯合表達出來,如=0C表示12。下面提供編碼及解碼的方式:

public static string EncodeQuotedPrintable(string value,bool isUtf8Encode) { if (string.IsNullOrEmpty(value)) return value; StringBuilder builder = new StringBuilder(); byte[] bytes = isUtf8Encode? Encoding.UTF8.GetBytes(value): Encoding.Default.GetBytes(value); foreach (byte v in bytes) { // The following are not required to be encoded: // - Tab (ascii 9) // - Space (ASCII 32) // - Characters 33 to 126, except for the equal sign (61). if ((v == 9) || ((v >= 32) && (v <= 60)) || ((v >= 62) && (v <= 126))) { builder.Append(Convert.ToChar(v)); } else { builder.Append('='); builder.Append(v.ToString("X2")); } } char lastChar = builder[builder.Length - 1]; if (char.IsWhiteSpace(lastChar)) { builder.Remove(builder.Length - 1, 1); builder.Append('='); builder.Append(((int)lastChar).ToString("X2")); } return builder.ToString(); } public static string DecodeQuotedPrintable(string input, string charSet) { Encoding enc; try { enc = Encoding.GetEncoding(charSet); } catch { enc = new UTF8Encoding(); } var occurences = new Regex(@"(=[0-9A-Z]{2}){1,}", RegexOptions.Multiline); var matches = occurences.Matches(input); foreach (Match match in matches) { try { byte[] b = new byte[match.Groups[0].Value.Length / 3]; for (int i = 0; i < match.Groups[0].Value.Length / 3; i ) { b[i] = byte.Parse(match.Groups[0].Value.Substring(i * 3 1, 2), System.Globalization.NumberStyles.AllowHexSpecifier); } char[] hexChar = enc.GetChars(b); input = input.Replace(match.Groups[0].Value, new String(hexChar)); } catch {; } } input = input.Replace("?=", "").Replace("\r\n", ""); return input; }

由于outlook 和Android 的解碼方式不同,所以在編碼的時候也需要注意,Android使用的是Utf-8, 而outlook 使用的是ascii,所以這裡需要注意; utf8占用3個字節,ascii 占用兩個字節;

下面是通過UTF-8生成出來 的

BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E5=B0=8F=E6=9B=BE TEL;CELL:13912341234 END:VCARD

下面是通過default (ASCII)生成出來 的

BEGIN:VCARD VERSION:2.1 N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D0=A1=D4=F8 TEL;CELL:13912341234 END:VCARD

注釋過的vcf文件怎麼分析(C生成vcf文件源代碼)1

完整源代碼見CSDN 搜索 C# 生成VCF demo源代碼,支持Android,outlook QuotedPrintable 中文編碼

或者私信給我

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
華為手機的哪個功能是開啟語音
華為手機的哪個功能是開啟語音
華為手機有很多好用的功能大家是知道的,那麼以下幾個功能你知道嗎?1.點外賣當你覺得想要點一個外賣,但是又懶得動怎麼辦,直接呼叫語音助手然後說出你想吃的東西,就ok啦!2.省電設置你還在為手機電量問題煩惱嗎?趕緊呼叫你的語音助手吧!瞬間幫你解...
2026-06-08
excel函數公式vlookup教程
excel函數公式vlookup教程
函數是Excel中應用非常廣泛的一個技巧,VLOOKUP函數更是許多白領的夢中情人……本節我們來學習關于VLOOKUP函數的那些神應用一、單條件查找。目的:查找對應人的成績。方法:在目标單元格中輸入公式:=VLOOKUP(H3,B3:C9,...
2026-06-08
迷你世界制作電腦屏幕小教程
迷你世界制作電腦屏幕小教程
大家好呐~我是六尾松,今天教大家做個簡單的電腦吧!先做個長10寬15的平面,可以噴上喜歡的顔色~然後複制一個一模一樣的,可以用藍圖工作台直接複制過來。(這就是鍵盤遼)接下來用硬沙塊在上面弄上不同的按鍵,可以是形狀各異的。再各幾個搭個電腦的架...
2026-06-08
更換手機微信聊天記錄能轉移嗎
更換手機微信聊天記錄能轉移嗎
安卓手機的微信如何将微信聊天記錄遷移到其他手機上?微信是一款火爆全球的社交應用工具,當你需要換手機時,你的微信聊天記錄該怎麼處理呢?當然是通過遷移解決了,安卓微信聊天記錄遷移,該怎麼做?如果你即将更換手機,舊手機的微信聊天記錄自然美是不會随...
2026-06-08
手機qq定時說說怎麼查看
手機qq定時說說怎麼查看
手機qq定時說說怎麼查看?首先找到手機中的QQ軟件,點擊打開QQ軟件,登錄個人賬号,然後點擊左上角的頭像,我來為大家講解一下關于手機qq定時說說怎麼查看?跟着小編一起來看一看吧!手機qq定時說說怎麼查看首先找到手機中的QQ軟件,點擊打開QQ...
2026-06-08
Copyright 2023-2026 - www.tftnews.com All Rights Reserved