Wednesday, March 28, 2012

String.split to a 2d array?

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!

MattString.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" <somedudeus@.yahoo.com> wrote in message
news:352b8dF4fa2viU1@.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
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" <somedudeus@.yahoo.com> wrote in message
> news:352b8dF4fa2viU1@.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
>

0 comments:

Post a Comment