Click here to Skip to main content
15,948,338 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a question here,

I have a text file of two columns, and up to 2000 rows and text file look like this.
actually, I logged the data in the text file

1 1
2 2
3 3
4 4
: :
: :
: :
100 100

I want to store the data of each column into two different arrays.
The arrays are of fixed length is it stores only 10 values while reading the text file. Once the 10 values get filled they arrays updates them with 10 news values.

What I have tried:

I don know how to do it please help
Updated 7-Sep-17 14:30pm
Dave Kreskowiak 5-Sep-17 22:53pm    
If we can't see your code we can't tell you what you're doing wrong.

No, we're not going to write your code for you. What would be the point of doing your work for you?
Graeme_Grant 5-Sep-17 22:55pm    
So column "a" gets stored in array "a" and column "b" is stored in array "b" but each array can only hold a maximum of 10 rows? Your example suggests that there are more than 10 rows?
SN25 7-Sep-17 20:27pm    
yes in my text file its has more than 10 rows..
Karthik_Mahalingam 6-Sep-17 0:49am    
Use Improve question to add more info to the question.
CPallini 6-Sep-17 3:11am    
Could please detail what are you unable to do? What is the main obstacle?

1 solution

This looks like homework, so I'll give you no code!
But it's very simple:
read the lines - you can do this in several ways, but the easiest is probably to use File.ReadAllLines which returns an array with each line of text in a separate array.
Then process each line. Since you are only interested in the last ten items, use the Length property of the array to find where the last ten starts.
For each line, use string.Split to break it into the two numbers, and use int.TryParse to convert each of the parts into a numeric value.
Store these in your two arrays.

Easy enough, if you take it stage by stage - it's probably less than ten lines of code in total!
Share this answer
SN25 7-Sep-17 3:57am    
it's not a home work I am working on a project and my question is one of the block of my code. I have to do tracking of object and for tracking of each object I am using the check box, when the check box is hit the tracking started and displays 10 track values.
Anyways I will try your approach, and If I have any problem I will share my code then.
Roberta Mafessoni 7-Sep-17 22:24pm    
Still looks like homework though.
Anyway the solution you got from OriginalGriff is very detailed and should be more than enough, but why aren't you using classes, lists, dictionaries and some more oop era techniques if you are doing such an advanced project. Just wondering. Good luck.
SN25 7-Sep-17 22:26pm    
Actually, I am a freshman to C# programming just going through all the stuff gradually,
never done C programming before
anyways thanks for the suggestion I will go through lists and classes as well
OriginalGriff 8-Sep-17 2:34am    
So, it's homework then ... if you are trying to learn by just "going through stuff" then stop right now, and get yourself a book or better a course. You need the material presented in a structured way which covers all the material and builds on previous knowledge. just "going through stuff" means you have no idea what you are missing out on, or why it's a good idea because you may never meet it or realise what it is when you do see it.
Roberta Mafessoni 8-Sep-17 14:21pm    
That is the best suggestion you will get.
Nice words OriginalGriff.
Thanks from me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900