Split Command AND an Array
| |
string[] fnames =newstring[8 ] { @"\\Share\File.rpt", @"\\Share\File.rpt", @"\\Share\File.rpt", @"\\Share\File.rpt", @"\\Share\File.rpt", @"\\\Share\File.rpt", @"\\Share\File.rpt", @"\\Share\File.rpt" }; int fcnt = 0; char delim = ' '; string rprtRead; string[] rprtARR =null; while (fcnt < 8) { using (FileStream fs =new FileStream(fnames[fcnt].ToString(), FileMode.Open, FileAccess.Read, FileShare.Read)) { using (StreamReader sr =new StreamReader(fs, Encoding.GetEncoding(437))) { rprtRead = sr.ReadToEnd(); rprtARR = rprtRead.Split(delim); } } fcnt++; }
|
On the line:
| |
rprtARR = rprtRead.Split(delim)
|
Everytime the loop repeats itself it re-wrties the full array. I need all the file contents stored in this one array. Is there anyways to do this? I am unable to do a
rprtARR[rprtArr.length] = rprtRead.Split(delim);
due to the fact that the compiler catches it as tieing a string[] to a string. Anyone have a way around this? Thanks in advance!
[1846 byte] By [
mEt] at [2007-12-23]
why don't you store it in an ArrayList?
ArrayList theList = new ArrayList();
so... in the using streamReader statement:
rprtRead = sr.ReadToEnd();
string[] rprtArr = rprtRead.Split(delim);
theArrayList.Add(rprtArr);
or if you need to use the string[] array try this (untested)
..
rprtArr[fcnt] = rprtRead.Split(delim);
but make sure you create the rprtArr[] array to the same length of fcnt
does this help/work for you?
I can go ahead and implement the ArrayList. From there I just need to be able to go back through and read through every entry in the ArrayList which is now 0-7. Is there a way to re-bind it back to an Array? Or are you familair with an easy way to go through all the entries? Thanks for your help.
BTW- The second method does not work because when you're sending the string to the array it cannot have any designation behind it, it can only be rprtARR = etc. or else it gives you an error stating that a string[] cannot be assigned a value from a string.
mEt at 2007-8-30 >

Actually, best case scenario would be I could take all the items in that Array list and bind them into a single array. So far everything I have tried has failed miserably though so any advice you could give would be greatly appreciated.
mEt at 2007-8-30 >

you are using many arrays which some of them pretty much hold the same thing (from what I understand)
you are probably safer/easier/quicker to just use an arraylist to store the string[] array's
or you could I guess create a string List<T> and add the items in there. Otherwise if you need to store them in the string[] array from the ArrayList:
| |
.. string[] theStringArrays = new string[theArrayList.Count]; for (int counter = 0; counter <= theArrayList.Count; counter++) { theStringArrays[counter] = theArrayList[counter].ToString(); }
|
does this help?
The code itself you gave me works but I don't think it's coded out exactly correct due to the way the arraylist is. My arraylist has a count of 8 (0-7).
arrlist[0] has 444285 dimensions
arrlist[1] has 105113 dimensions
arrlist[2] has 37655 dimensions
arrlist[3] has 131660 dimensions
arrlist[4] has 613290 dimensions
arrlist[5] has 582707 dimensions
arrlist
has 468240 dimensions
arrlist[7] has 605740 dimensions
What my code actually does is go through each of these individual items looking for certain strings. Here is the code:
| |
while (i != rprtARR2.Length) { entry = rprtARR2 .ToString(); if (entry == "PANEL" || entry == "SWBD") { i++; entry = rprtARR2 .ToString(); if (entry == "SCHEDULE:") { i++; entry = rprtARR2 .ToString(); if (entry == panel) { i++; while (entry != "\r\n\f\r\n") { result = result + " " + rprtARR .ToString(); i++; entry = rprtARR .ToString(); } } } } i++; } l = 0; if (result == null) { } else { while (l < result.Length) { reportTextBox.Text = result; l++; } }
|
Of course I am willing to modify this code as needed I just don't know how to get it to sort through that arraylist. As you can see from the code I was originally checking the data from a single string[] array.
mEt at 2007-8-30 >
