By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

String.split to a 2d array?

P: n/a
I have a list of states and abbreviations that I want to be able to pull
into a 2d array to bind to a control. The list looks like this:

AL:Alabama,AK:Alaska,AZ:Arizona,...

So If I take the starting and split it on the comma, it gives me a 1d
array with XX:Name in each element. Is there any easy way (like split)
to do this into a 2d array, so I end up with:

aStates(0,0)="AL"
aStates(0,1)="Alabama"

and so on...

I know a number of ways I could code this up to make it work but I'm
wondering if there's a nice quick n' dirty way using split or something
similar. Thanks!

Matt
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
String.Split allows you to pass in more than one delimiter. Maybe what you
could do is to figure that all even indexes are the state code and all odd
indexes are the state name.

"MattB" <so********@yahoo.com> wrote in message
news:35*************@individual.net...
I have a list of states and abbreviations that I want to be able to pull
into a 2d array to bind to a control. The list looks like this:

AL:Alabama,AK:Alaska,AZ:Arizona,...

So If I take the starting and split it on the comma, it gives me a 1d
array with XX:Name in each element. Is there any easy way (like split)
to do this into a 2d array, so I end up with:

aStates(0,0)="AL"
aStates(0,1)="Alabama"

and so on...

I know a number of ways I could code this up to make it work but I'm
wondering if there's a nice quick n' dirty way using split or something
similar. Thanks!

Matt

Nov 19 '05 #2

P: n/a
Thanks. I considered that but decided on making a DataTable, looping
through the first array from splitting on the comma, and splitting a
second time on the colon and loading the table row that way.
Works well, I just wanted to see if I was overlooking a really easy
shortcut.

Matt

Peter Rilling wrote:
String.Split allows you to pass in more than one delimiter. Maybe what you
could do is to figure that all even indexes are the state code and all odd
indexes are the state name.

"MattB" <so********@yahoo.com> wrote in message
news:35*************@individual.net...
I have a list of states and abbreviations that I want to be able to pull
into a 2d array to bind to a control. The list looks like this:

AL:Alabama,AK:Alaska,AZ:Arizona,...

So If I take the starting and split it on the comma, it gives me a 1d
array with XX:Name in each element. Is there any easy way (like split)
to do this into a 2d array, so I end up with:

aStates(0,0)="AL"
aStates(0,1)="Alabama"

and so on...

I know a number of ways I could code this up to make it work but I'm
wondering if there's a nice quick n' dirty way using split or something
similar. Thanks!

Matt


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.