-
January 9th, 2009, 04:09 PM
#1
2-D Array
using VS9.0, C#
I am having a tough time getting my data into an array. I am reading data from a serial port. I get a long string that looks like so:
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
I want an array that looks like this:
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n, (one record)
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
XXXX, XX/XX/XX, XX:XX, XXXXXXXX\r\n,
There is no way to tell how many records will be coming in...the max amount is 300
I am using the serialPort's datareceived event to grab the string...I have an idea how I think I can get what I want:
1) take the long string and spilt it at each '\r\n' to make a 1-d array**
2) count the number of elements in that array (to get number of records for 2-d array initializing)
3) get a 2-d array [numOfRecords, 4]
4) spilt each element of the 1-d array at each ',' and put into the new 2-d array
**where I got stuck (don't know how many records...can't set size of array...now, i am lost).
if anyone has a good idea how I can do this...or any suggestions, it would be much appreciated.
Thanks!
(PS. I would post my code...but it's a big load of crap that doesn't work...i'm ashamed)
-
January 9th, 2009, 04:31 PM
#2
Re: 2-D Array
changing your structure into 4 generic lists and coupling them with indices would be an offer.
Please rate my post if it was helpful for you. Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
January 9th, 2009, 05:13 PM
#3
Re: 2-D Array
Originally Posted by toraj58
changing your structure into 4 generic lists and coupling them with indices would be an offer.
I agree that using a dynamic class (such as List<T>) would be a good way to go, but would almost definately go in the opposite direction
Code:
class ARecord
{
public string Part1 {get; set;}
public string Part2 {get; set;}
public string Part3 {get; set;}
}
class MyData : List<ARecord> {}
MUCH easier to work with...
Code:
var foo = from myData where p.Part1.Contains("Foo") select p;
ps: I think the word you meant was either "option" or "alternative."..
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|