Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB4,VB5,VB6,VBS
Expertise: Intermediate
Apr 1, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

JoinQuote2 - A Join variant that works with 2-dimensional arrays and quoted strings

' Join variant that works with
' bi-dimensional arrays of any type
' and that encloses string values between quotes
' ARR is the 2-dimensional array whose element must be joined
' ROWSEPARATOR is the separator for rows (default is CRLF)
' COLSEPARATOR is the separator fol columns (default is comma)
' QUOTED is the character used to quote string values
'     use a two-char string (eg "{}") if the openining
'     and closing quote chars are different
'     use a null string to suppress quoting feature

Function JoinQuoted2(arr As Variant, Optional ByVal RowSeparator As String = _
    vbCrLf, Optional ByVal ColSeparator As String = ",", _
    Optional ByVal Quotes As String = """") As String
    Dim res As String
    Dim r As Long
    Dim c As Long
    For r = LBound(arr) To UBound(arr)
        For c = LBound(arr, 2) To UBound(arr, 2)
            If VarType(arr(r, c)) <> vbString Then
                res = res & arr(r, c)
                ' the following code works correctly if
                ' LEN(Quotes) is 0,1,2
                res = res & Left$(Quotes, 1) & arr(r, c) & Right$(Quotes, 1)
            End If
            If c < UBound(arr, 2) Then res = res & ColSeparator
        If r < UBound(arr) Then res = res & RowSeparator
    JoinQuoted2 = res

End Function

Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date