split a string into an arraylist?

M

Mad Scientist Jr

If I try splitting a string into an arraylist

Dim arrList As New ArrayList
arrList = Split("a,b,c", ",")

I get this error: Value of type '1-dimensional array of String' cannot
be converted to 'System.Collections.ArrayList'.

How can I split a string into an arraylist?

Thanks
 
A

Armin Zingler

Mad Scientist Jr said:
If I try splitting a string into an arraylist

Dim arrList As New ArrayList
arrList = Split("a,b,c", ",")

I get this error: Value of type '1-dimensional array of String'
cannot be converted to 'System.Collections.ArrayList'.

How can I split a string into an arraylist?

arrlist.addrange(Split("a,b,c", ","))



Armin
 
P

Phill W.

Mad Scientist Jr said:
If I try splitting a string into an arraylist

Dim arrList As New ArrayList
arrList = Split("a,b,c", ",")

I get this error: Value of type '1-dimensional array of String' cannot
be converted to 'System.Collections.ArrayList'.

Aren't Constructors Wonderful things?

Creating a new ArrayList /based on/ a String array:

Dim arrList As New ArrayList( "a,b,c".Split( ","c ) )

or, to split by a multiple-character delimiter:

Imports VB=Microsoft.VisualBasic

Dim arrList As New ArrayList( VB.Split( "a<>b<>c", "<>" ) )

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top