vCard Reader Class

None.gif Imports  System.IO
ExpandedBlockStart.gifContractedBlock.gif
Public   Class vCardReader Class vCardReader
ExpandedSubBlockStart.gifContractedSubBlock.gif
Define#Region "Define"
InBlock.gif    
Public vCards As vCard()
ExpandedSubBlockEnd.gif
#End Region

ExpandedSubBlockStart.gifContractedSubBlock.gif
Subs#Region "Subs"
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Sub New()Sub New(ByVal vCardFileStream As FileStream)
InBlock.gif        DecodeVCardFromFileStream(vCardFileStream)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Function Split()Function Split(ByVal Content As StringAs CardProperty
InBlock.gif        
Dim CardProperty As CardProperty
InBlock.gif        
Dim PropertyAndParametreString As String = Content.Split(":")(0)
InBlock.gif        
Dim ValueString As String = Content.Split(":")(1)
InBlock.gif        
Dim Temp As String() = PropertyAndParametreString.Split(";")
InBlock.gif        CardProperty.Name 
= Temp(0)
InBlock.gif        
If Temp.Length > 1 Then
InBlock.gif            
ReDim CardProperty.Parametres(Temp.GetUpperBound(0- 1)
InBlock.gif            Temp.Copy(Temp, 
1, CardProperty.Parametres, 0, Temp.Length - 1)
InBlock.gif        
Else
InBlock.gif            CardProperty.Parametres 
= Nothing
InBlock.gif        
End If
InBlock.gif        CardProperty.Values 
= ValueString.Split(";")
InBlock.gif        
Return CardProperty
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub DecodeVCardFromFileStream()Sub DecodeVCardFromFileStream(ByVal vCardFileStream As FileStream)
InBlock.gif        
Dim Reader As New StreamReader(vCardFileStream)
InBlock.gif        
ReDim vCards(0)
InBlock.gif        
Dim CurrentVcard As Integer
InBlock.gif        
Do
InBlock.gif            
'Search for vCard
InBlock.gif
            ReDim vCards(CurrentVcard).Properties(-1)
InBlock.gif            
If InStr(Reader.ReadLine, "BEGIN:VCARD"Then
InBlock.gif                
'Start Processing vCard object
InBlock.gif
                Dim Content As String
InBlock.gif                
Dim cardProperty As CardProperty
InBlock.gif                
Do
InBlock.gif                    Content 
= Reader.ReadLine
InBlock.gif                    
If Content = "END:VCARD" Then Exit Do
InBlock.gif                    
'The "=" in then end of a stream indicates message is not complete. Read next line and contact them.
InBlock.gif
                    Do
InBlock.gif
InBlock.gif                        
If Content.LastIndexOf("="= Content.Length - 1 Then
InBlock.gif                            Content 
= Content.Substring(0, Content.Length - 2+ Reader.ReadLine
InBlock.gif                        
Else : Exit Do
InBlock.gif                        
End If
InBlock.gif                    
Loop
InBlock.gif                    
'Split properties , parametres and values.
InBlock.gif
                    cardProperty = Split(Content)
InBlock.gif                    
Dim PropertyNumber As Integer = vCards(CurrentVcard).Properties.Length
InBlock.gif                    
ReDim Preserve vCards(CurrentVcard).Properties(PropertyNumber)
InBlock.gif                    vCards(CurrentVcard).Properties(PropertyNumber) 
= cardProperty
InBlock.gif                
Loop
InBlock.gif            
End If
InBlock.gif            
If Reader.Peek() < 0 Then
InBlock.gif                
Return
InBlock.gif            
End If
InBlock.gif            CurrentVcard 
+= 1
InBlock.gif            
ReDim Preserve vCards(CurrentVcard)
InBlock.gif        
Loop
ExpandedSubBlockEnd.gif    
End Sub

ExpandedSubBlockEnd.gif
#End Region

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Structures#Region "Structures"
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Structure vCardStructure vCard
InBlock.gif        
Public Properties As CardProperty()
ExpandedSubBlockEnd.gif    
End Structure

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Structure CardPropertyStructure CardProperty
InBlock.gif        
Public Name As String
InBlock.gif        
Public Parametres() As String
InBlock.gif        
Public Values() As String
ExpandedSubBlockEnd.gif    
End Structure

InBlock.gif
ExpandedSubBlockEnd.gif
#End Region

InBlock.gif
ExpandedBlockEnd.gif
End Class

None.gif
None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值