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: VB7
Expertise: beginner
Dec 23, 2002



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

ConcatenateStrings - Concatenating an array of strings

' Concatenate the input strings, and return the resulting string. The first 
' input string is used as a separator.
' Example:
'   Dim i As Integer = 4
'   Dim d As Double = 34.45
'   Dim s As String = "VB-2-The-Max"
'   Dim ret As String = ConcatenateStrings(" ", s, "is a nice site, ins't it?",
'  "It has been online for", i, "years.", "Just test the function with a Double 
' now:", d)
'   MessageBox.Show(ret)

Function ConcatenateStrings(ByVal sep As String, ByVal ParamArray args() As _
    Object) As String
    Dim builder As New System.Text.StringBuilder()
    ' add each item of the input array to the StringBuilder's string
    Dim o As Object
    For Each o In args
        If builder.Length > 0 Then
            ' add the separator if this is not the first item we add
        End If
    ' return the final string
    Return builder.ToString()
End Function

' If all arguments are strings, then the following method is simpler and faster:

Function ConcatenateStrings2(ByVal sep As String, ByVal ParamArray args()
As String) As String
    Return String.Join(sep, args)
End Function
Marco Bellinaso
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