Convert string array to string in VB

3

I need to use SPLIT on a lot of data, but I need to convert the array string to string.

I'm putting String () to get the string array variable, but VS keeps telling me that one-dimensional array can not be converted to string.

Can anyone help me?

    
asked by anonymous 28.04.2016 / 18:30

2 answers

2

You can use the String.Join method that you expect a separator, and parameters to concatenate and return a string (a collection in general). Example:

Dim result as String = String.Join("", array)
    
28.04.2016 / 18:38
2

Catharina is not very clear about the situation you have, so it is difficult to give a categorical answer.

To concatenate items in an array in a single String, without tabs, you can use the # a>

To concatenate items in an array into a single string, including a separator string, the method, already indicated by others, is Join ()

To complete with items in an array a preformatted string, the preferred method is p>

Now you mentioned that you need to use SPLIT and I did not understand it, because #

does exactly the opposite: it divides a String into several fragments and returns an Array.

Here are some examples. If you put your code here, it makes it much easier to give an answer.

Sub ExemplosStringArray()
    Dim arrayOfString As String() = {"aaaa", "bbbb", "cccc"}
    Dim concatStrings = String.Concat(arrayOfString)
    MsgBox(concatStrings)
    Dim joinedStrings = Join(arrayOfString, ";")
    MsgBox(joinedStrings)
    Dim formattedString = String.Format("Temos {0}, {1} e finalmente {2}", arrayOfString)
    MsgBox(formattedString)
    Dim multipartString = "dddd-eeee+ffff"  
    Dim arrayFromString = multipartString.Split("-"c, "+"c)
    Dim newStringFromArray = Join(arrayFromString, vbCrLf)
    MsgBox(newStringFromArray)
End Sub
    
31.05.2016 / 00:32
Bookmarks specific lines Visual Studio If fclose closes a file, how do you close an open file with the SplFileObject object?