Convert Arraylist to string in vb.net

How to convert arraylist to comma delimited string in vb.net

I have an arraylist with identity values

arr(0)=1
arr(1)=2
arr(2)=3

I want to convert it to string

Dim str as string=""
str="1,2,3"
+3
source share
4 answers
str = string.Join(",", arr.ToArray());

If you need to convert the List to a string [] before the string. Can do

Array.ConvertAll<int, string>(str.ToArray(), new Converter<int, string>(Convert.ToString));

So...

str = string.Join(",", Array.ConvertAll<int, string>(str.ToArray(), new Converter<int, string>(Convert.ToString)));
+6
source

As an answer, here you can try:

Dim s As String = String.Join(",", TryCast(arr.ToArray(GetType(String)), String()))

Hope this helps if he really votes.

+1
source

GetType Join.

Dim S = YourArrayList.ToArray(Type.GetType("System.String"))
MessageBox.Show(String.Join(",", S))

FOR EACH . ( )

Dim S as string = ""
For Each item As String In YourArrayList
    S &= item & ", "
Next
MessageBox.Show(S)
+1
0
source

Source: https://habr.com/ru/post/1734895/


All Articles