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

需要需要生成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
推荐阅读
超好看ipad電腦壁紙
超好看ipad電腦壁紙
,
2026-06-15
重裝系統xp
重裝系統xp
重裝系統xp?重裝系統前确認有兩個以上硬盤分區打開“小白一鍵重裝系統”,會自動搜索可用的系統,選擇你想安裝的系統,點擊“安裝此系統”,下面我們就來聊聊關于重裝系統xp?接下來我們就一起去了解一下吧!重裝系統xp重裝系統前确認有兩個以上硬盤分...
2026-06-15
手機投屏到電視機是什麼原理
手機投屏到電視機是什麼原理
手機投屏到電視機是什麼原理?手機投屏原理是就是使用無線傳輸方式将手機設備中的圖像數據傳輸到電腦屏幕上,實際上就是通過WiFi進行傳輸,在行業術語上稱作為“Miracast”,簡單的說就是“Miracast”通過“WiFiDisplay”認證...
2026-06-15
手機花屏解決方法
手機花屏解決方法
手機花屏解決方法?關閉手機,折下電池,過會再安裝上電池,重新開機,試一下看能否解決問題,今天小編就來聊一聊關于手機花屏解決方法?接下來我們就一起去研究一下吧!手機花屏解決方法關閉手機,折下電池,過會再安裝上電池,重新開機,試一下看能否解決問...
2026-06-15
榮耀x10用的是骁龍750g嗎
榮耀x10用的是骁龍750g嗎
自2019年6月5G牌照正式發放以來,各大手機廠商相繼推出各自5G新品。然而,市場中琳琅滿目的5G手機卻并未引發想象中的5G換機潮。前段時間,榮耀總裁趙明也表示:如今仍有70%的消費者換機時選擇4G手機。究其原因,還是現階段的5G手機價格昂...
2026-06-15
Copyright 2023-2026 - www.tftnews.com All Rights Reserved