首页
/
每日頭條
/
科技
/
注釋過的vcf文件怎麼分析
注釋過的vcf文件怎麼分析
更新时间:2026-11-04 06:44:20

需要需要生成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、鼠标單擊桌面左下角的“開始菜單”,點擊齒輪圖标進入設置面闆。2、點擊“設備”,點擊“自動播放”,...
2026-11-04
秋天空調制熱多少度合适
秋天空調制熱多少度合适
空調制熱20度合适。因為冬天時候室内溫度20℃不僅是最适最溫暖的溫度,還可以避免空調超負荷作業,對人的身體也有利。空調即空氣調節器(AirConditioner)。是指用人工手段,對建築或構築物内環境空氣的溫度、濕度、流速等參數進行調節和控制的設備。一般包括冷源/熱源設備,冷熱介質輸配系統,末端裝置等幾大部分和其他輔助設備。主要包括,制冷主機、水泵、風機和管路系統。末端裝置則負責利用輸配來的冷熱量
2026-11-04
學習java需要哪些基礎知識
學習java需要哪些基礎知識
1、HTML+CSS+DIV,前端會用到,作為研發人員至少應該會簡單寫些頁面出來,這是許多編程語言都...
2026-11-04
iphone7plus屏幕尺寸
iphone7plus屏幕尺寸
iPhone7Plus屏幕尺寸為5.5英寸。iPhone7Plus是蘋果7升級手機,北京時間2016年9月8日2016蘋果秋季新品發布會上發布。iPhone7Plus屏幕大小5.5英寸,擁有雙1200萬像素攝像頭,虛化效果自然,亮度提升了25%,色彩更佳。揚聲器升級,采用上下立體聲的揚聲器。取消了3.5mm耳機接口,推出全新耳機AppleAirPods。2016年9月9日開啟預約,9月16日正式開
2026-11-04
為什麼電視不能投屏
為什麼電視不能投屏
1、手機中的一些配置出錯,重新配置一下即可,或者就是手機沒有和電視機保持在同一局域網内。确認下你的手...
2026-11-04
Copyright 2023-2026 - www.tftnews.com All Rights Reserved