last day (15 days later) » 

2:56 PM
0
Q: New Blank 2D array without size in C#

Richeek DeyI need to create an array for which I do not know the size in advance. I used the following, but it gives an index out of bounds error in my for -loop. string[] arr = s.Split('\n'); int[] indices = new int[arr.Length]; string[][] new_arr = new string[arr.Length][]; ...

 
But this is 1D no?
 
Yes but with List it will be a 1D list?
 
@RicheekDey Yes, you can make an array of lists or a list of lists to make it multi-dimensional
 
Ah, but I'm new to C#. hence I wanna keep it simple. Arrays I know. Lists...not really.
 
2:56 PM
Do you need to have a multidimensional array? What are you trying to achieve?
What do need to do eventually?
 
Hey, I need a 2 D array yes. So what I have currently is a string (which I have converted to a string array)
I separated it using \n
so now i wish to have a 2d array
wherein each column starts with "21"
and there are n columns.
i will show you my text file, 1 sec
the blue marks, thats where i want my column to begin. and each column should contain the data from that particular 21 until the next occurence of 21
 
one line should be one string?
 
so column 0 will be 21,22,23,31,32,31,31
and column 1 will be 21
and column 2 will be 21, 22,23,31
thoase are only the starting numbers, the entire line should be one entire row
 
I really can't understand why do you need a multidimensional array
 
okay, how would you suggest this then?
 
3:02 PM
do you need each line in beginning with 21 in an array or what exactly?
 
i need each line that begins with a 21 in one row of an array
and each column has to begin with 21
so it is 2d array grouped in terms of 21
 
Sorry, but it's really confusing
Can you write or draw the result you want to achieve?
with just basic data, not everything
 
like this
 
Oh
So you want lines with 21 in a column until you find next row with a 21 in the beginning
 
yes
and each column has that data, the screenshot i sent you before
each row of that column is 130 chars, its a string
 
3:16 PM
I'll try to write something to help you
 
i will send you what i have done so far
string[] arr = s.Split('\n');
so now assume arr[] contains all the elements in a string array where each element of the array is a new line of text (just like the screenshot I sent you )
 
Alright, I have something like this:
string[] arr = "21\n214\n5621".Split('\n');
.
. List<List<string>> listOfLists = new List<List<string>>();
.
. List<string> newList = new List<string>();
. for(int i = 0; i < arr.Length; i++)
. {
. if(arr[i].StartsWith("21"))
. {
. if(newList.Count > 0)
. listOfLists.Add(newList);
. newList = new List<string>();
. }
. newList.Add(arr[i]);
. }
. if(newList.Count > 0)
. listOfLists.Add(newList);
wait I need to format it
I'll post it as an answer, I can format it there
 
Alright.
@RicheekDey doesn't work how? this looks exactly like what you requested — Default 1 hour ago
you can post it as an answer to this one :)
1
Q: Split Array into 2D based on 2 parameters C#

Richeek DeyI have a text file which I have split up into a string array based on new line. string[] arr = s.Split('\n'); Now, I need to further categorize this into a 2-dimensional array wherein each column is a new "transaction". So the text file basically contains info about bank transactions, an exam...

hey, you there? :)
 
3:35 PM
yeah I posted it
 
uhm, i dont see it. :(
okay now i do
ill try it, one sec :)
listoflists is the main list right?
 
yeah
I made it a little bit simpler now
 
omg. thank you so much. i was struggling with this since friday. you are a true life saviour sir!
can i pick your brain about more of this later perhaps?
i am new to C# and dont know much, so i do really appreciate this help.
 
yeah ask away
 
okay great, for now i shall try parsing the data ( that is my main aim), i shall come to you in case i get stuck. Once again, thanks a bunch.
 

  last day (15 days later) »