首页
/
每日頭條
/
科技
/
注釋過的vcf文件怎麼分析
注釋過的vcf文件怎麼分析
更新时间:2025-12-27 15:07:28

需要需要生成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
推荐阅读
廢舊手機怎麼安全處理
廢舊手機怎麼安全處理
廢舊手機怎麼安全處理?随着智能手機的不斷普及和推陳出新,一些市民家裡閑置的廢舊手機也越來越多,然而,這些廢舊手機如何處理,卻讓不少人感到為難12月25日,市民許先生整理物品時,發現閑置多年的舊手機有五部,今天小編就來說說關于廢舊手機怎麼安全...
2025-12-27
linux mint如何使用
linux mint如何使用
藍點網昨天已經提到LinuxMint19.2正式版向所有用戶推出帶來更好的桌面環境,新版本帶來桌面更新和管理器更新等。如果你已經常年使用Windows10想要換個系統體驗下,那麼不妨跟随這篇教程安裝LinuxMint19.2試試。當然在虛拟...
2025-12-27
航拍剪輯畫面靜止
航拍剪輯畫面靜止
·解決飛行器振動方法當分析出振動是造成全屏果凍效應的原因後,我們就有了明确的努力方向,那就是飛機的“排震”。飛機的機架、電機、雲台、相機和一些不起眼的小零件都有可能是振動的來源。每個飛行器和不同型号的雲台、相機都會有不同的振動。如何才能解決...
2025-12-27
虛拟現實的發展過程
虛拟現實的發展過程
FBEC2020|北京航空航天大學國家重點實驗室副教授潘俊君:虛拟現實的未來發展趨勢及應用12月11日,2020未來商業生态鍊接大會暨第五屆金陀螺獎頒獎典禮(簡稱“FBEC2020”)在深圳大中華喜來登酒店6樓宴會廳開幕。本屆大會由中國通信...
2025-12-27
最好用的新款5g手機
最好用的新款5g手機
諾基亞今天淩晨發布了諾基亞8.3、諾基亞5.3在内的多款産品,其中諾基亞8.3是諾基亞旗下首款5G設備。此外,諾基亞還将5310XpressMusic進行了複刻,依然主打音樂播放。作為諾基亞首款5G智能手機,諾基亞8.3采用高通骁龍765G...
2025-12-27
Copyright 2023-2025 - www.tftnews.com All Rights Reserved