473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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!

Matt
Nov 19 '05 #1
2 2091
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
5
by: Ann Marinas | last post by:
Happy New Year to all! :D I am currently developoing an application that imports data from a CSV file. Each comma represents an array item that I need to extract data with. My problem is...
7
by: Mad Scientist Jr | last post by:
I have been doing this kind of thing in VB and VB.net for a long time, but am having problems in C#: First I want to split up a string by the backslash character, but this line: arrSplit =...
4
by: J | last post by:
anybody know a vb.net command to populate an array with each word in a string? for example " hi how are you" array(0) = hi array(1) = how array(2) = are array(3) = you i know i could...
6
by: Bruce Wiebe | last post by:
Hi all I have a string that contains a list of email addresses in the format {"X@y.com","x@y.com"} and i need to convert it to a string array in the same format so my array would loook like ...
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
17
by: AMP | last post by:
Hello I get 2 errors in the following code that I cant Debug without some help. They are both in the TryParse function. Seems simple enough.The Errors are Below. private void...
12
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
14
by: Stevo | last post by:
If you split a string into an array using the split method, it's not working the way I'd expect it to. That doesn't mean it's wrong of course, but would anyone else agree it's working somewhat...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.