VCard Reader Class

xiaoxiao2021-03-06  72

Imports System.iopublic Class VcardReader # Region "Define" public vcards as vcard () # End Region # region "SUBS"

Sub New (Byval VcardFileStream As FileStream) DecodevcardFromFileStream (vcardFileStream) End Sub

Private Function Split (ByVal Content As String) As CardProperty Dim CardProperty As CardProperty Dim PropertyAndParametreString As String = Content.Split ( ":") (0) Dim ValueString As String = Content.Split ( ":") (1) Dim Temp As String () = PropertyAndParametreString.Split ( ";") CardProperty.Name = Temp (0) If Temp.Length> 1 Then ReDim CardProperty.Parametres (Temp.GetUpperBound (0) - 1) Temp.Copy (Temp, 1, CardProperty .Parametres, 0, Temp.length - 1) Else cardproperty.Parametres = Nothing end if cardproperty.values ​​= valueString.split (";") Return CardProperty End Function

Public Sub DecodeVCardFromFileStream (ByVal vCardFileStream As FileStream) Dim Reader As New StreamReader (vCardFileStream) ReDim vCards (0) Dim CurrentVcard As Integer Do 'Search for vCard ReDim vCards (CurrentVcard) .Properties (-1) If InStr (Reader.ReadLine, " BEGIN: VCARD ") Then 'Start Processing vCard object Dim Content As String Dim cardProperty As CardProperty Do Content = reader.ReadLine If Content =" END: VCARD "Then Exit Do' The" = "in then end of a stream indicates message is NOT NEXT LINE and Contact Them. DO

If Content.LastIndexOf ( "=") = Content.Length - 1 Then Content = Content.Substring (0, Content.Length - 2) Reader.ReadLine Else: Exit Do End If Loop 'Split properties, parametres and values ​​cardProperty. = Split (Content) Dim PropertyNumber As Integer = vCards (CurrentVcard) .Properties.Length ReDim Preserve vCards (CurrentVcard) .Properties (PropertyNumber) vCards (CurrentVcard) .Properties (PropertyNumber) = cardProperty Loop End If If Reader.Peek () < 0 THEN RETURN END IF CURRENTVCARD = 1 Redim Preserve Vcards (Currentvcard) Loop End Sub # End Region # Region "Structure" Public Structure Vcard Public Properties as cardproperty () end structure

Public structure cardproperty public name as string public parametres () AS string public value () AS STRING End Structure

#End region

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-92242.html

New Post(0)