Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

what is the most efficient way to convert an array into string

       Dim intArr() = {1, 2, 3}

        MsgBox(Convert.ToString(intArr)) does not work
        MsgBox(Convert.ToString(CObj(intArr))) either

0
AlexF777
Asked:
AlexF777
  • 2
3 Solutions
 
DarrenDCommented:
If you have three array items thn you have to output them as follows

MsgBox(intArr(0).ToString))

Or if you want to convert the array to 'String' type

This might work


Dim arrStr() as string = CType(intArr, String)
0
 
VBRocksCommented:
You can just use the Join method:

    MsgBox(Join(intArr, ","))

0
 
VBRocksCommented:
You know, if your array is of the Type Integer, then you may need to take this kind of an approach:

    'This sub is not required, but put the code in whatever sub you want to show the message in.
    Private Sub ShowArray()
        Dim intArr() As Integer = {1, 2, 3}
        Dim str As String() = Array.ConvertAll(Of Integer, String)(intArr, AddressOf IntToString)

        MsgBox(Join(str, ","))

    End Sub


    'This sub is required
    Private Shared Function IntToString(ByVal i As Integer) As String

        Return CType(i, String)

    End Function

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now