VCard reader class

Source: Internet
Author: User
Imports System. Io
Public   Class vcardreader Class Vcardreader
Define # Region"Define"
PublicVcardsAsVCard ()
# End Region
Subs # Region "Subs"

Sub new () Sub New(ByvalVcardfilestreamAsFilestream)
Decodevcardfromfilestream (vcardfilestream)
End sub

Private   Function split () 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 () 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 complete. read 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

Structures # Region "Structures"
Public   Structure vCard StructureVCard
PublicPropertiesAsCardproperty ()
End Structure

Public   Structure cardproperty Structure Cardproperty
Public Name As   String
Public Parametres () As   String
Public Values () As   String
End Structure

# End Region

End Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.