首页
/
每日頭條
/
科技
/
注釋過的vcf文件怎麼分析
注釋過的vcf文件怎麼分析
更新时间:2026-07-13 16:45:54

需要需要生成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
推荐阅读
北京零基礎前端軟件培訓班學習怎麼樣
北京零基礎前端軟件培訓班學習怎麼樣
随着開發市場的不斷發展,市場上學習開發技術的人越來越多,前端開發程序員是越來越多,但是這也并不是意味着前端開發技術的就業達到了飽和,現在企業在招聘程序員的時候,對學曆和實戰經驗的要求越來越高,小夥伴想要找到更好更合适的工作,還需要提高學習效...
2026-07-13
oppo堅持手機拍照r11s将成經典
oppo堅持手機拍照r11s将成經典
OPPO手機一直以出色的拍攝性能受到消費者的青睐,每一代機型在拍攝性能上都有着不俗的表現。新機型R11更是以前後兩千萬雙攝的配置,将OPPO手機的拍攝性能提升到了新的高度。今天我們就來和大家一起回顧一下,那些擁有出色拍攝性能曾經打動你的OP...
2026-07-13
微型電腦主機測評
微型電腦主機測評
電腦的誕生便利了很多人群,但随着持續發展,電腦肯定也不是一成不變的,從第一台電腦開始,電腦從體積到性能都發生了很大的變化,從台式電腦到筆記本電腦,體積越來越小巧精緻,配置也越來越高端。如今滿足部分用戶需求,又推出了微型小主機,可以自由攜帶,...
2026-07-13
kindle能不能看epub格式的書
kindle能不能看epub格式的書
公司經常有Kindle小白問我怎麼用Kindle看epub文件,每個人都說一遍,挺麻煩的。所以寫個簡單的教程,幫助大家簡簡單單,開始用Kindle“打開”epub電子書。簡單說明1.Kindle原生是不支持epub的,它隻支持mobi和az...
2026-07-13
兩個版本的嫦娥你喜歡哪個
兩個版本的嫦娥你喜歡哪個
嫦娥是在神話劇中出場幾乎是最多的一位仙子,嫦娥在觀衆心目中是冰冷的,不食人間煙火的,今天小編就帶大家盤點一下演過嫦娥的10位女演員吧。第一位是在《春光燦爛豬八戒》中飾演嫦娥的陳紅,她在劇中的氣質渾然天成,她的美是一種典雅的美,劇中的她淡妝出...
2026-07-13
Copyright 2023-2026 - www.tftnews.com All Rights Reserved