<%@ Page %>
HOW TO: Quickly convert ArrayList into Delimited String
ArrayList provides good way to store list of objects. Some times ArrayLists containing strings need to be converted in delimited strings. Consider for example that you have written a component that returns an ArrayList containing list of email addresses. Now you want to convert that into a comma
separated string so that you can set it to TO, CC or BCC properties of your email component. This How To will show you how to achieve that without iterating through the ArrayList.
Dim arrLst As New ArrayList()
Dim strFinal As String
Dim strarr() As String
strarr = arrLst.ToArray(Type.GetType("System.String"))
strFinal = String.Join(",", strarr)
Here, we have created an arraylist arrLst that contains three email addresses. The ToArray method of ArayList class returns its content in the form of array of given type. Since we are storing strings we specified "System.String". So we will get string array in our case. The String class has a static method called Join that joins array elements separated with
supplied delimiter and returns the resultant string.