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.
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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)
NP. Glad to help :)
ASKER
strString = " String.Join("', '", arrArrayList.ToArray) + "'"
Thank you.