Link to home
Create AccountLog in
Avatar of Rick
Rick

asked on

asp.net - arraylist to comma delimited string

I have an ArrayList with x number of items.
I would like to convert this ArrayList into a comma delimited string.
In addition, each item must be surrounded by single quotes.

This is what I have so far:

            strString = String.Join(",", arrArrayList.ToArray)

This gives me:

            strString = "item1, item2, item3, item4"


This is what I need:

            strString = "'item1', 'item2', 'item3', 'item4'"



Thank you.
SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Rick
Rick

ASKER

I almost had it.

strString = " String.Join("', '", arrArrayList.ToArray) + "'"

Thank you.


You could loop the array and quote the strings one at a time:
Dim a() As Object = arrArrayList.ToArray

		For i As Integer = 0 To a.Count - 1
			a(i) = String.Format("'{0}'", a(i))
		Next

		strString = String.Join(",", a)

Open in new window

NP. Glad to help  :)