How do I convert an arraylist into a string of comma delimated values in vb.net
I have an arraylist with ID values
arr(0)=1
arr(1)=2
arr(2)=3
I want to convert it into a string
Dim str as string=""
str="1,2,3"
str = string.Join(",", arr.ToArray());
If you need to convert the List to string[] before the string.Join you 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)));
You can simply achieve it from GetType and Join Functions.
Dim S = YourArrayList.ToArray(Type.GetType("System.String"))
MessageBox.Show(String.Join(",", S))
Another way is to use FOR EACH Statement to read and store each item of array one by one in a delimited string. (But not recommended)
Dim S as string = ""
For Each item As String In YourArrayList
S &= item & ", "
Next
MessageBox.Show(S)
typeof(String).As the answer here you can try:
Dim s As String = String.Join(",", TryCast(arr.ToArray(GetType(String)), String()))
Use String.Join with a comma delimeter (http://msdn.microsoft.com/en-us/library/57a79xd0.aspx)